mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#21002: EMail with CC Bcc etc.
Merge branch 'IBN-Labs/MailPlusCC' of https://git01.codeplex.com/forks/qt1/orchad4ibn into PR Conflicts: src/Orchard.Web/Modules/Orchard.Email/Services/SmtpMessageChannel.cs Work Item: 21002
This commit is contained in:
@@ -4,7 +4,8 @@
|
|||||||
public string Body { get; set; }
|
public string Body { get; set; }
|
||||||
public string Recipients { get; set; }
|
public string Recipients { get; set; }
|
||||||
public string ReplyTo { get; set; }
|
public string ReplyTo { get; set; }
|
||||||
|
public string From { get; set; }
|
||||||
public string Bcc { get; set; }
|
public string Bcc { get; set; }
|
||||||
public string CC { get; set; }
|
public string Cc { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -22,6 +22,7 @@ namespace Orchard.Email.Services {
|
|||||||
IOrchardServices orchardServices,
|
IOrchardServices orchardServices,
|
||||||
IShapeFactory shapeFactory,
|
IShapeFactory shapeFactory,
|
||||||
IShapeDisplay shapeDisplay) {
|
IShapeDisplay shapeDisplay) {
|
||||||
|
|
||||||
_shapeFactory = shapeFactory;
|
_shapeFactory = shapeFactory;
|
||||||
_shapeDisplay = shapeDisplay;
|
_shapeDisplay = shapeDisplay;
|
||||||
|
|
||||||
@@ -39,7 +40,6 @@ namespace Orchard.Email.Services {
|
|||||||
|
|
||||||
public void Process(IDictionary<string, object> parameters) {
|
public void Process(IDictionary<string, object> parameters) {
|
||||||
|
|
||||||
|
|
||||||
if (!_smtpSettings.IsValid()) {
|
if (!_smtpSettings.IsValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -49,8 +49,9 @@ namespace Orchard.Email.Services {
|
|||||||
Subject = Read(parameters, "Subject"),
|
Subject = Read(parameters, "Subject"),
|
||||||
Recipients = Read(parameters, "Recipients"),
|
Recipients = Read(parameters, "Recipients"),
|
||||||
ReplyTo = Read(parameters, "ReplyTo"),
|
ReplyTo = Read(parameters, "ReplyTo"),
|
||||||
|
From = Read(parameters, "From"),
|
||||||
Bcc = Read(parameters, "Bcc"),
|
Bcc = Read(parameters, "Bcc"),
|
||||||
CC = Read(parameters, "CC")
|
Cc = Read(parameters, "CC")
|
||||||
};
|
};
|
||||||
|
|
||||||
if (emailMessage.Recipients.Length == 0) {
|
if (emailMessage.Recipients.Length == 0) {
|
||||||
@@ -58,7 +59,7 @@ namespace Orchard.Email.Services {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Applying default Body alteration for SmtpChannel
|
// Apply default Body alteration for SmtpChannel.
|
||||||
var template = _shapeFactory.Create("Template_Smtp_Wrapper", Arguments.From(new {
|
var template = _shapeFactory.Create("Template_Smtp_Wrapper", Arguments.From(new {
|
||||||
Content = new MvcHtmlString(emailMessage.Body)
|
Content = new MvcHtmlString(emailMessage.Body)
|
||||||
}));
|
}));
|
||||||
@@ -69,18 +70,55 @@ namespace Orchard.Email.Services {
|
|||||||
IsBodyHtml = true
|
IsBodyHtml = true
|
||||||
};
|
};
|
||||||
|
|
||||||
var section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
|
if (parameters.ContainsKey("Message")) {
|
||||||
mailMessage.From = !String.IsNullOrWhiteSpace(_smtpSettings.Address)
|
// A full message object is provided by the sender.
|
||||||
? new MailAddress(_smtpSettings.Address)
|
|
||||||
: new MailAddress(section.From);
|
var oldMessage = mailMessage;
|
||||||
|
mailMessage = (MailMessage)parameters["Message"];
|
||||||
|
|
||||||
|
if (String.IsNullOrWhiteSpace(mailMessage.Subject))
|
||||||
|
mailMessage.Subject = oldMessage.Subject;
|
||||||
|
|
||||||
|
if (String.IsNullOrWhiteSpace(mailMessage.Body)) {
|
||||||
|
mailMessage.Body = oldMessage.Body;
|
||||||
|
mailMessage.IsBodyHtml = oldMessage.IsBodyHtml;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
foreach (var recipient in emailMessage.Recipients.Split(new [] {',', ';'}, StringSplitOptions.RemoveEmptyEntries)) {
|
|
||||||
|
foreach (var recipient in ParseRecipients(emailMessage.Recipients)) {
|
||||||
|
mailMessage.To.Add(new MailAddress(recipient));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!String.IsNullOrWhiteSpace(emailMessage.Cc)) {
|
||||||
|
foreach (var recipient in ParseRecipients(emailMessage.Cc)) {
|
||||||
|
mailMessage.CC.Add(new MailAddress(recipient));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!String.IsNullOrWhiteSpace(emailMessage.Bcc)) {
|
||||||
|
foreach (var recipient in ParseRecipients(emailMessage.Bcc)) {
|
||||||
|
mailMessage.Bcc.Add(new MailAddress(recipient));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!String.IsNullOrWhiteSpace(emailMessage.From)) {
|
||||||
|
mailMessage.From = new MailAddress(emailMessage.From);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Take 'From' address from site settings or web.config.
|
||||||
|
mailMessage.From = !String.IsNullOrWhiteSpace(_smtpSettings.Address)
|
||||||
|
? new MailAddress(_smtpSettings.Address)
|
||||||
|
: new MailAddress(((SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp")).From);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var recipient in ParseRecipients(emailMessage.Recipients)) {
|
||||||
mailMessage.To.Add(new MailAddress(recipient));
|
mailMessage.To.Add(new MailAddress(recipient));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!String.IsNullOrWhiteSpace(emailMessage.ReplyTo)) {
|
if (!String.IsNullOrWhiteSpace(emailMessage.ReplyTo)) {
|
||||||
foreach (var recipient in emailMessage.ReplyTo.Split(new [] {',', ';'}, StringSplitOptions.RemoveEmptyEntries)) {
|
foreach (var recipient in ParseRecipients(emailMessage.ReplyTo)) {
|
||||||
mailMessage.ReplyToList.Add(new MailAddress(recipient));
|
mailMessage.ReplyToList.Add(new MailAddress(recipient));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +131,7 @@ namespace Orchard.Email.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private SmtpClient CreateSmtpClient() {
|
private SmtpClient CreateSmtpClient() {
|
||||||
// if no properties are set in the dashboard, use the web.config value
|
// If no properties are set in the dashboard, use the web.config value.
|
||||||
if (String.IsNullOrWhiteSpace(_smtpSettings.Host)) {
|
if (String.IsNullOrWhiteSpace(_smtpSettings.Host)) {
|
||||||
return new SmtpClient();
|
return new SmtpClient();
|
||||||
}
|
}
|
||||||
@@ -119,5 +157,9 @@ namespace Orchard.Email.Services {
|
|||||||
private string Read(IDictionary<string, object> dictionary, string key) {
|
private string Read(IDictionary<string, object> dictionary, string key) {
|
||||||
return dictionary.ContainsKey(key) ? dictionary[key] as string : null;
|
return dictionary.ContainsKey(key) ? dictionary[key] as string : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<string> ParseRecipients(string recipients) {
|
||||||
|
return recipients.Split(new[] {',', ';'}, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user