mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-15 15:21:09 +08:00
Re-applying logic to send attachments from 46c3fe6e79
This commit is contained in:
parent
0fb45b445a
commit
c8c5196b18
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Configuration;
|
||||
using System.Net.Mail;
|
||||
@ -55,7 +56,11 @@ namespace Orchard.Email.Services {
|
||||
FromAddress = Read(parameters, "FromAddress"),
|
||||
FromName = Read(parameters, "FromName"),
|
||||
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)) {
|
||||
@ -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();
|
||||
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user