mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 20:09:09 +08:00
parent
72062399ed
commit
46c3fe6e79
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Hosting;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Email.Models;
|
||||
@ -52,11 +53,7 @@ namespace Orchard.Email.Controllers {
|
||||
else {
|
||||
_smtpChannel.Process(new Dictionary<string, object> {
|
||||
{"Recipients", testSettings.To},
|
||||
{"Subject", testSettings.Subject},
|
||||
{"Body", testSettings.Body},
|
||||
{"ReplyTo", testSettings.ReplyTo},
|
||||
{"Bcc", testSettings.Bcc},
|
||||
{"CC", testSettings.Cc}
|
||||
{"Subject", T("Orchard CMS - SMTP settings test email").Text}
|
||||
});
|
||||
}
|
||||
|
||||
@ -64,10 +61,10 @@ namespace Orchard.Email.Controllers {
|
||||
return Json(new { error = fakeLogger.Message });
|
||||
}
|
||||
|
||||
return Json(new {status = T("Message sent.").Text});
|
||||
return Json(new { status = T("Message sent.").Text });
|
||||
}
|
||||
catch (Exception e) {
|
||||
return Json(new {error = e.Message});
|
||||
return Json(new { error = e.Message });
|
||||
}
|
||||
finally {
|
||||
var smtpChannelComponent = _smtpChannel as Component;
|
||||
@ -94,7 +91,6 @@ namespace Orchard.Email.Controllers {
|
||||
|
||||
public class TestSmtpSettings {
|
||||
public string From { get; set; }
|
||||
public string ReplyTo { get; set; }
|
||||
public string Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
public bool EnableSsl { get; set; }
|
||||
@ -103,10 +99,6 @@ namespace Orchard.Email.Controllers {
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string To { get; set; }
|
||||
public string Cc { get; set; }
|
||||
public string Bcc { get; set; }
|
||||
public string Subject { get; set; }
|
||||
public string Body { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
namespace Orchard.Email.Models {
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.Email.Models {
|
||||
public class EmailMessage {
|
||||
public string Subject { get; set; }
|
||||
public string Body { get; set; }
|
||||
@ -7,5 +9,9 @@
|
||||
public string From { get; set; }
|
||||
public string Bcc { get; set; }
|
||||
public string Cc { get; set; }
|
||||
/// <summary>
|
||||
/// IEnumerable of strings representing attachments paths
|
||||
/// </summary>
|
||||
public IEnumerable<string> Attachments { get; set; }
|
||||
}
|
||||
}
|
@ -9,6 +9,8 @@ using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Email.Models;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
namespace Orchard.Email.Services {
|
||||
public class SmtpMessageChannel : Component, ISmtpChannel, IDisposable {
|
||||
@ -51,7 +53,8 @@ namespace Orchard.Email.Services {
|
||||
ReplyTo = Read(parameters, "ReplyTo"),
|
||||
From = Read(parameters, "From"),
|
||||
Bcc = Read(parameters, "Bcc"),
|
||||
Cc = Read(parameters, "CC")
|
||||
Cc = Read(parameters, "CC"),
|
||||
Attachments = (IEnumerable<string>)(parameters.ContainsKey("Attachments") ? parameters["Attachments"] : new List<string>())
|
||||
};
|
||||
|
||||
if (emailMessage.Recipients.Length == 0) {
|
||||
@ -119,6 +122,14 @@ namespace Orchard.Email.Services {
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var attachmentPath in emailMessage.Attachments) {
|
||||
if (File.Exists(attachmentPath)) {
|
||||
mailMessage.Attachments.Add(new Attachment(attachmentPath));
|
||||
}
|
||||
else {
|
||||
throw new FileNotFoundException(T("One or more attachments not found.").Text);
|
||||
}
|
||||
}
|
||||
_smtpClientField.Value.Send(mailMessage);
|
||||
}
|
||||
catch (Exception e) {
|
||||
@ -129,7 +140,7 @@ namespace Orchard.Email.Services {
|
||||
private SmtpClient CreateSmtpClient() {
|
||||
// If no properties are set in the dashboard, use the web.config value.
|
||||
if (String.IsNullOrWhiteSpace(_smtpSettings.Host)) {
|
||||
return new SmtpClient();
|
||||
return new SmtpClient();
|
||||
}
|
||||
|
||||
var smtpClient = new SmtpClient {
|
||||
@ -155,7 +166,7 @@ namespace Orchard.Email.Services {
|
||||
}
|
||||
|
||||
private IEnumerable<string> ParseRecipients(string recipients) {
|
||||
return recipients.Split(new[] {',', ';'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
return recipients.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
}
|
||||
}
|
@ -72,25 +72,6 @@
|
||||
<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="emailtestreplyto">@T("Reply To:")</label>
|
||||
<input type="text" id="emailtestreplyto" class="large text" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="emailtestsubject">@T("Subject:")</label>
|
||||
<input type="text" id="emailtestsubject" class="large text" />
|
||||
</div>
|
||||
<div>
|
||||
<textarea id="emailtestbody"></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" id="emailtestsend" class="button grey">@T("Send")</button>
|
||||
</div>
|
||||
@ -111,12 +92,7 @@
|
||||
useDefaultCredentials = $("input[name='@Html.NameFor(m => m.UseDefaultCredentials)']"),
|
||||
userName = $("#@Html.FieldIdFor(m => m.UserName)"),
|
||||
password = $("#@Html.FieldIdFor(m => m.Password)"),
|
||||
to = $("#emailtestto"),
|
||||
subject = $("#emailtestsubject"),
|
||||
body = $("#emailtestbody"),
|
||||
replyto = $("#emailtestreplyto"),
|
||||
bcc = $("#emailtestbcc"),
|
||||
cc = $("#emailtestcc");
|
||||
to = $("#emailtestto");
|
||||
|
||||
$("#emailtestsend").click(function () {
|
||||
$.post(url, {
|
||||
@ -129,11 +105,6 @@
|
||||
userName: userName.val(),
|
||||
password: password.val(),
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user