Re-applying logic to send attachments from 46c3fe6e79

This commit is contained in:
Benedek Farkas 2024-03-08 18:50:07 +01:00
parent 0fb45b445a
commit c8c5196b18

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration; using System.Configuration;
using System.IO;
using System.Linq; using System.Linq;
using System.Net.Configuration; using System.Net.Configuration;
using System.Net.Mail; using System.Net.Mail;
@ -55,7 +56,11 @@ namespace Orchard.Email.Services {
FromAddress = Read(parameters, "FromAddress"), FromAddress = Read(parameters, "FromAddress"),
FromName = Read(parameters, "FromName"), FromName = Read(parameters, "FromName"),
Bcc = Read(parameters, "Bcc"), Bcc = Read(parameters, "Bcc"),
Cc = Read(parameters, "CC") Cc = Read(parameters, "CC"),
Attachments = (IEnumerable<string>)(parameters.ContainsKey("Attachments")
? parameters["Attachments"]
: new List<string>()
)
}; };
if (string.IsNullOrWhiteSpace(emailMessage.Recipients)) { if (string.IsNullOrWhiteSpace(emailMessage.Recipients)) {
@ -87,6 +92,15 @@ namespace Orchard.Email.Services {
} }
} }
foreach (var attachmentPath in emailMessage.Attachments) {
if (File.Exists(attachmentPath)) {
mailBodyBuilder.Attachments.Add(attachmentPath);
}
else {
throw new FileNotFoundException(T("One or more attachments not found.").Text);
}
}
mailMessage.Body = mailBodyBuilder.ToMessageBody(); mailMessage.Body = mailBodyBuilder.ToMessageBody();
try { try {