This commit is contained in:
2022-03-07 23:01:49 +00:00
parent 5f01dda11a
commit ca9ee50332
2 changed files with 9 additions and 8 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);
Task SendEmailAsync(string email, string subject, string body, AyaNova.Models.GlobalOpsNotificationSettings smtpSettings, string attachPDF = null, string forceFileName = 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)
public async Task SendEmailAsync(string email, string subject, string body, AyaNova.Models.GlobalOpsNotificationSettings smtpSettings, string attachPDFPath = null, string forceFileName = null)
{
try
{
@@ -29,17 +29,18 @@ namespace AyaNova.Util
message.Subject = subject;
if (!string.IsNullOrWhiteSpace(attachPDFPath))
{
{
var attachment = new MimePart("application/pdf", "pdf")
{
Content = new MimeContent(File.OpenRead(attachPDFPath), ContentEncoding.Default),
ContentDisposition = new ContentDisposition(ContentDisposition.Attachment),
ContentTransferEncoding = ContentEncoding.Base64,
FileName = Path.GetFileName("test.pdf")
//FileName = Path.GetFileName(attachPDFPath)
FileName = Path.GetFileName(attachPDFPath)
};
if (!string.IsNullOrWhiteSpace(forceFileName))
attachment.FileName = forceFileName;
var multipart = new Multipart("mixed");
if (!string.IsNullOrWhiteSpace(body))
multipart.Add(new TextPart(TextFormat.Plain) { Text = body });