case 4310

This commit is contained in:
2022-11-21 00:25:14 +00:00
parent 334e00ba43
commit f412e6a66b
2 changed files with 27 additions and 19 deletions

View File

@@ -9,7 +9,7 @@ namespace AyaNova.Util
{
public interface IMailer
{
Task SendEmailAsync(string email, string subject, string body, AyaNova.Models.GlobalOpsNotificationSettings smtpSettings, string attachPDF = null, string forceFileName = null);
Task SendEmailAsync(string email, string subject, string body, AyaNova.Models.GlobalOpsNotificationSettings smtpSettings, string attachPDF = null, string forceFileName = null, string htmlBody = null);
}
public class Mailer : IMailer
@@ -19,7 +19,7 @@ namespace AyaNova.Util
}
public async Task SendEmailAsync(string email, string subject, string body, AyaNova.Models.GlobalOpsNotificationSettings smtpSettings, string attachPDFPath = null, string forceFileName = null)
public async Task SendEmailAsync(string email, string subject, string body, AyaNova.Models.GlobalOpsNotificationSettings smtpSettings, string attachPDFPath = null, string forceFileName = null, string htmlBody = null)
{
try
{
@@ -49,8 +49,18 @@ namespace AyaNova.Util
}
else
{
// if (!string.IsNullOrWhiteSpace(body))
// message.Body = new TextPart(TextFormat.Plain) { Text = body };
MimeKit.BodyBuilder builder = new BodyBuilder();
if (!string.IsNullOrWhiteSpace(body))
message.Body = new TextPart(TextFormat.Plain) { Text = body };
builder.TextBody = body;
if (!string.IsNullOrWhiteSpace(htmlBody))
builder.HtmlBody = htmlBody;
message.Body = builder.ToMessageBody();
}
using (var client = new SmtpClient())
@@ -67,7 +77,7 @@ namespace AyaNova.Util
DisposeStreamsInMimeMessage(message);
}
}
catch (Exception e)
{
@@ -75,7 +85,7 @@ namespace AyaNova.Util
}
}
public static void DisposeStreamsInMimeMessage(MimeMessage msg) { foreach (var part in msg.BodyParts) (part as MimePart)?.Content?.Stream?.Dispose(); }
public static void DisposeStreamsInMimeMessage(MimeMessage msg) { foreach (var part in msg.BodyParts) (part as MimePart)?.Content?.Stream?.Dispose(); }
}
}