Some additions and improvements to Email module

- Added support for bcc and cc while sending emails.
- Applied fix for replyto field : https://orchard.codeplex.com/workitem/21103
This commit is contained in:
abhishekluv
2014-12-07 01:38:54 +05:30
parent 6340e504bc
commit 61bfb14bb3
6 changed files with 61 additions and 8 deletions

View File

@@ -55,12 +55,16 @@ namespace Orchard.Email.Activities {
var subject = activityContext.GetState<string>("Subject");
var recipients = activityContext.GetState<string>("Recipients");
var replyTo = activityContext.GetState<string>("ReplyTo");
var bcc = activityContext.GetState<string>("Bcc");
var cc = activityContext.GetState<string>("CC");
var parameters = new Dictionary<string, object> {
{"Subject", subject},
{"Body", body},
{"Recipients", recipients},
{"ReplyTo", replyTo}
{"ReplyTo", replyTo},
{"Bcc", bcc},
{"CC", cc}
};
var queued = activityContext.GetState<bool>("Queued");

View File

@@ -18,7 +18,7 @@ namespace Orchard.Email.Controllers {
public Localizer T { get; set; }
public ActionResult TestMailSettings(string to, string subject, string body) {
public ActionResult TestMailSettings(string to, string subject, string body, string replyTo, string bcc, string cc) {
ILogger logger = null;
try {
var fakeLogger = new FakeLogger();
@@ -30,7 +30,10 @@ namespace Orchard.Email.Controllers {
_smtpChannel.Process(new Dictionary<string, object> {
{"Recipients", to},
{"Subject", subject},
{"Body", body}
{"Body", body},
{"ReplyTo",replyTo},
{"Bcc", bcc},
{"CC",cc}
});
if (!string.IsNullOrEmpty(fakeLogger.Message)) {
return Json(new { error = fakeLogger.Message });

View File

@@ -36,12 +36,24 @@ namespace Orchard.Email.Forms {
Title: T("Email Addresses"),
Description: T("Specify a comma-separated list of recipient email addresses. To include a display name, use the following format: John Doe &lt;john.doe@outlook.com&gt;"),
Classes: new[] {"large", "text", "tokenized"}),
_Bcc: New.TextBox(
Id: "bcc",
Name: "Bcc",
Title: T("Bcc"),
Description: T("If necessary, specify an email address for a blind carbon copy"),
Classes: new[]{"large","text","tokenized"}),
_CC: New.TextBox(
Id: "cc",
Name: "CC",
Title: T("CC"),
Description: T("If necessary, specify an email address for a carbon copy"),
Classes: new[] { "large", "text", "tokenized" }),
_ReplyTo: New.Textbox(
Id: "reply-to",
Name: "ReplyTo",
Title: T("Reply To Address"),
Description: T("If necessary, specify an email address for replies."),
Classes: new [] {"medium", "text", "tokenized"}),
Classes: new [] {"large", "text", "tokenized"}),
_Subject: New.Textbox(
Id: "Subject", Name: "Subject",
Title: T("Subject"),
@@ -93,6 +105,7 @@ namespace Orchard.Email.Forms {
var recipients = context.ValueProvider.GetValue("Recipients").AttemptedValue;
var subject = context.ValueProvider.GetValue("Subject").AttemptedValue;
var body = context.ValueProvider.GetValue("Body").AttemptedValue;
if (String.IsNullOrWhiteSpace(recipients)) {
context.ModelState.AddModelError("Recipients", T("You must specify at least one recipient.").Text);

View File

@@ -4,5 +4,7 @@
public string Body { get; set; }
public string Recipients { get; set; }
public string ReplyTo { get; set; }
public string Bcc { get; set; }
public string CC { get; set; }
}
}

View File

@@ -48,7 +48,9 @@ namespace Orchard.Email.Services {
Body = parameters["Body"] as string,
Subject = parameters["Subject"] as string,
Recipients = parameters["Recipients"] as string,
ReplyTo = parameters["ReplyTo"] as string
ReplyTo = parameters["ReplyTo"] as string,
Bcc = parameters["Bcc"] as string,
CC = parameters["CC"] as string
};
if (emailMessage.Recipients.Length == 0) {
@@ -77,8 +79,18 @@ namespace Orchard.Email.Services {
mailMessage.To.Add(new MailAddress(recipient));
}
if (!String.IsNullOrWhiteSpace(emailMessage.ReplyTo)) {
mailMessage.ReplyToList.Add(new MailAddress(emailMessage.ReplyTo));
foreach (var replyTo in emailMessage.ReplyTo.Split(new[] {',', ';'}, StringSplitOptions.RemoveEmptyEntries)) {
mailMessage.ReplyToList.Add(new MailAddress(replyTo));
}
foreach (var bcc in emailMessage.Bcc.Split(new[] {',', ';'}, StringSplitOptions.RemoveEmptyEntries))
{
mailMessage.Bcc.Add(new MailAddress(bcc));
}
foreach (var cc in emailMessage.CC.Split(new[] {',', ';'},
StringSplitOptions.RemoveEmptyEntries)) {
mailMessage.CC.Add(new MailAddress(cc));
}
_smtpClientField.Value.Send(mailMessage);

View File

@@ -56,10 +56,22 @@
<label for="emailtestto">@T("To:")</label>
<input type="text" id="emailtestto" class="large text" />
</div>
<div>
<label for="emailtestbcc">@T("Bcc:")</label>
<input type="text" id="emailtestbcc" class="large text" />
</div>
<div>
<label for="emailtestcc">@T("CC:")</label>
<input type="text" id="emailtestcc" class="large text" />
</div>
<div>
<label for="emailtestsubject">@T("Subject:")</label>
<input type="text" id="emailtestsubject" class="large text" />
</div>
<div>
<label for="emailtestreplyto">@T("Reply To:")</label>
<input type="text" id="emailtestreplyto" class="large text" />
</div>
<div>
<textarea id="emailtestbody"></textarea>
</div>
@@ -76,12 +88,19 @@
info = $("#emailtestinfo"),
to = $("#emailtestto"),
subject = $("#emailtestsubject"),
body = $("#emailtestbody");
body = $("#emailtestbody"),
replyto = $("#emailtestreplyto"),
bcc = $("#emailtestbcc"),
cc = $("#emailtestcc");
$("#emailtestsend").click(function() {
$.post(url, {
to: to.val(),
subject: subject.val(),
body: body.val(),
replyto: replyto.val(),
bcc: bcc.val(),
cc: cc.val(),
__RequestVerificationToken: to.closest("form").find("input[name=__RequestVerificationToken]").val()
})
.fail(function(data) {