Skip to content

Commit

Permalink
Merge branch 'main' into ma/fix-azure-ai-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored May 18, 2024
2 parents 454ab20 + c5acb34 commit f7e53d2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,7 @@ internal static async Task<bool> SendEmailAsync(this Controller controller, stri
body = sw.ToString();
}

var message = new MailMessage()
{
To = email,
Subject = subject,
Body = body,
IsHtmlBody = true
};

var result = await emailService.SendAsync(message);
var result = await emailService.SendAsync(email, subject, body);

return result.Succeeded;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,11 @@ public async Task<IActionResult> RequestCode()
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user);

var settings = (await SiteService.GetSiteSettingsAsync()).As<EmailAuthenticatorLoginSettings>();
var message = new MailMessage()
{
To = await UserManager.GetEmailAsync(user),
Subject = await GetSubjectAsync(settings, user, code),
Body = await GetBodyAsync(settings, user, code),
IsHtmlBody = true,
};

var result = await _emailService.SendAsync(message);
var to = await UserManager.GetEmailAsync(user);
var subject = await GetSubjectAsync(settings, user, code);
var body = await GetBodyAsync(settings, user, code);
var result = await _emailService.SendAsync(to, subject, body);

if (!result.Succeeded)
{
Expand Down Expand Up @@ -170,15 +166,10 @@ public async Task<IActionResult> SendCode()
var settings = (await SiteService.GetSiteSettingsAsync()).As<EmailAuthenticatorLoginSettings>();
var code = await UserManager.GenerateTwoFactorTokenAsync(user, TokenOptions.DefaultEmailProvider);

var message = new MailMessage()
{
To = await UserManager.GetEmailAsync(user),
Subject = await GetSubjectAsync(settings, user, code),
Body = await GetBodyAsync(settings, user, code),
IsHtmlBody = true,
};

var result = await _emailService.SendAsync(message);
var to = await UserManager.GetEmailAsync(user);
var subject = await GetSubjectAsync(settings, user, code);
var body = await GetBodyAsync(settings, user, code);
var result = await _emailService.SendAsync(to, subject, body);

return Ok(new
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,7 @@ public override async Task<ActivityExecutionResult> ExecuteAsync(WorkflowExecuti

var body = await _expressionEvaluator.EvaluateAsync(ConfirmationEmailTemplate, workflowContext, _htmlEncoder);

var message = new MailMessage()
{
To = email,
Subject = subject,
Body = body,
IsHtmlBody = true
};

var result = await _emailService.SendAsync(message);
var result = await _emailService.SendAsync(email, subject, body);

if (!result.Succeeded)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Threading.Tasks;

namespace OrchardCore.Email;

/// <summary>
/// Provides extension methods to <see cref="ISmtpService"/>.
/// </summary>
public static class EmailServiceExtensions
{
/// <summary>
/// Sends the specified message to an SMTP server for delivery.
/// </summary>
/// <param name="emailService">The <see cref="IEmailService"/>.</param>
/// <param name="to">The email recipients.</param>
/// <param name="subject">The email subject.</param>
/// <param name="body">The email body.</param>
/// <param name="isHtmlBody">Whether the <paramref name="body"/> is in HTML format or not. Defaults to <c>true</c>.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentException"></exception>
public static Task<EmailResult> SendAsync(this IEmailService emailService, string to, string subject, string body, bool isHtmlBody = true)
{
var message = new MailMessage
{
To = to,
Subject = subject,
Body = body,
IsHtmlBody = isHtmlBody
};

return emailService.SendAsync(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,21 @@ public async Task<bool> TrySendAsync(object notify, INotificationMessage message
return false;
}

var mailMessage = new MailMessage()
{
To = user.Email,
Subject = message.Subject,
};

string body;
bool isHtmlBody;

if (message.IsHtmlPreferred && !string.IsNullOrWhiteSpace(message.HtmlBody))
{
mailMessage.Body = message.HtmlBody;
mailMessage.IsHtmlBody = true;
body = message.HtmlBody;
isHtmlBody = true;
}
else
{
mailMessage.Body = message.TextBody;
mailMessage.IsHtmlBody = false;
body = message.TextBody;
isHtmlBody = false;
}

var result = await _emailService.SendAsync(mailMessage);
var result = await _emailService.SendAsync(user.Email, message.Subject, body, isHtmlBody);

return result.Succeeded;
}
Expand Down

0 comments on commit f7e53d2

Please sign in to comment.