mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-21 11:14:03 +08:00
Adding email template wrappers
This commit is contained in:
@@ -79,6 +79,7 @@
|
|||||||
<Compile Include="Rules\MailActions.cs" />
|
<Compile Include="Rules\MailActions.cs" />
|
||||||
<Compile Include="Rules\MailForms.cs" />
|
<Compile Include="Rules\MailForms.cs" />
|
||||||
<Compile Include="Services\DefaultEmailMessageChannelSelector.cs" />
|
<Compile Include="Services\DefaultEmailMessageChannelSelector.cs" />
|
||||||
|
<Compile Include="Services\ISmtpChannel.cs" />
|
||||||
<Compile Include="Services\SmtpMessageChannel.cs" />
|
<Compile Include="Services\SmtpMessageChannel.cs" />
|
||||||
<Compile Include="Services\EmailMessageEventHandler.cs" />
|
<Compile Include="Services\EmailMessageEventHandler.cs" />
|
||||||
<Compile Include="Services\EmailMessagingChannel.cs" />
|
<Compile Include="Services\EmailMessagingChannel.cs" />
|
||||||
@@ -129,6 +130,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\Activity-SendEmail.cshtml" />
|
<Content Include="Views\Activity-SendEmail.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Views\Template.Smtp.Wrapper.cshtml" />
|
||||||
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
using Orchard.ContentManagement;
|
using Orchard.Messaging.Services;
|
||||||
using Orchard.Email.Models;
|
|
||||||
using Orchard.Messaging.Services;
|
|
||||||
|
|
||||||
namespace Orchard.Email.Services {
|
namespace Orchard.Email.Services {
|
||||||
public class DefaultEmailMessageChannelSelector : Component, IMessageChannelSelector {
|
public class DefaultEmailMessageChannelSelector : Component, IMessageChannelSelector {
|
||||||
private readonly IOrchardServices _services;
|
private readonly IWorkContextAccessor _workContextAccessor;
|
||||||
public const string ChannelName = "Email";
|
public const string ChannelName = "Email";
|
||||||
|
|
||||||
public DefaultEmailMessageChannelSelector(IOrchardServices services) {
|
public DefaultEmailMessageChannelSelector(IWorkContextAccessor workContextAccessor) {
|
||||||
_services = services;
|
_workContextAccessor = workContextAccessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageChannelSelectorResult GetChannel(string messageType, object payload) {
|
public MessageChannelSelectorResult GetChannel(string messageType, object payload) {
|
||||||
if (messageType == "Email") {
|
if (messageType == "Email") {
|
||||||
|
var workContext = _workContextAccessor.GetContext();
|
||||||
|
var channel = workContext.Resolve<ISmtpChannel>();
|
||||||
return new MessageChannelSelectorResult {
|
return new MessageChannelSelectorResult {
|
||||||
Priority = 50,
|
Priority = 50,
|
||||||
MessageChannel = new SmtpMessageChannel(_services.WorkContext.CurrentSite.As<SmtpSettingsPart>())
|
MessageChannel = channel
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
using Orchard.Messaging.Services;
|
||||||
|
|
||||||
|
namespace Orchard.Email.Services {
|
||||||
|
public interface ISmtpChannel : IMessageChannel {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,29 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Mail;
|
using System.Net.Mail;
|
||||||
|
using System.Web.Mvc;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.DisplayManagement;
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.Email.Models;
|
using Orchard.Email.Models;
|
||||||
using Orchard.Messaging.Services;
|
|
||||||
|
|
||||||
namespace Orchard.Email.Services {
|
namespace Orchard.Email.Services {
|
||||||
public class SmtpMessageChannel : Component, IMessageChannel, IDisposable {
|
public class SmtpMessageChannel : Component, ISmtpChannel, IDisposable {
|
||||||
private readonly SmtpSettingsPart _smtpSettings;
|
private readonly SmtpSettingsPart _smtpSettings;
|
||||||
|
private readonly IShapeFactory _shapeFactory;
|
||||||
|
private readonly IShapeDisplay _shapeDisplay;
|
||||||
private readonly Lazy<SmtpClient> _smtpClientField;
|
private readonly Lazy<SmtpClient> _smtpClientField;
|
||||||
public static readonly string MessageType = "Email";
|
public static readonly string MessageType = "Email";
|
||||||
|
|
||||||
public SmtpMessageChannel(SmtpSettingsPart smtpSettings) {
|
public SmtpMessageChannel(
|
||||||
_smtpSettings = smtpSettings;
|
IOrchardServices orchardServices,
|
||||||
|
IShapeFactory shapeFactory,
|
||||||
|
IShapeDisplay shapeDisplay) {
|
||||||
|
_shapeFactory = shapeFactory;
|
||||||
|
_shapeDisplay = shapeDisplay;
|
||||||
|
|
||||||
|
_smtpSettings = orchardServices.WorkContext.CurrentSite.As<SmtpSettingsPart>();
|
||||||
_smtpClientField = new Lazy<SmtpClient>(CreateSmtpClient);
|
_smtpClientField = new Lazy<SmtpClient>(CreateSmtpClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,6 +36,8 @@ namespace Orchard.Email.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Process(string payload) {
|
public void Process(string payload) {
|
||||||
|
|
||||||
|
|
||||||
if (!_smtpSettings.IsValid()) {
|
if (!_smtpSettings.IsValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -40,11 +52,16 @@ namespace Orchard.Email.Services {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Applying default Body alteration for SmtpChannel
|
||||||
|
var template = _shapeFactory.Create("Template_Smtp_Wrapper", Arguments.From(new {
|
||||||
|
Content = new MvcHtmlString(emailMessage.Body)
|
||||||
|
}));
|
||||||
|
|
||||||
var mailMessage = new MailMessage {
|
var mailMessage = new MailMessage {
|
||||||
From = new MailAddress(_smtpSettings.Address),
|
From = new MailAddress(_smtpSettings.Address),
|
||||||
Subject = emailMessage.Subject,
|
Subject = emailMessage.Subject,
|
||||||
Body = emailMessage.Body,
|
Body = _shapeDisplay.Display(template),
|
||||||
IsBodyHtml = emailMessage.Body != null && emailMessage.Body.Contains("<") && emailMessage.Body.Contains(">")
|
IsBodyHtml = true
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
@* Override this template to alter the email messages sent by the Smtp channel *@
|
||||||
|
<p style="font-family: 'Segoe UI', Arial, helvetica, sans-serif; font-size: 10pt; ">
|
||||||
|
@Model.Content
|
||||||
|
</p>
|
||||||
@@ -167,6 +167,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\Template.User.LostPassword.cshtml" />
|
<Content Include="Views\Template.User.LostPassword.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Views\Template.User.Wrapper.cshtml" />
|
||||||
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
|||||||
@@ -109,6 +109,8 @@ namespace Orchard.Users.Services {
|
|||||||
var recipient = GetUser(userName);
|
var recipient = GetUser(userName);
|
||||||
if (recipient != null) {
|
if (recipient != null) {
|
||||||
var template = _shapeFactory.Create("Template_User_Moderated", Arguments.From(createUserParams));
|
var template = _shapeFactory.Create("Template_User_Moderated", Arguments.From(createUserParams));
|
||||||
|
template.Metadata.Wrappers.Add("Template_User_Wrapper");
|
||||||
|
|
||||||
var payload = new {
|
var payload = new {
|
||||||
Subject = T("New account").Text,
|
Subject = T("New account").Text,
|
||||||
Body = _shapeDisplay.Display(template),
|
Body = _shapeDisplay.Display(template),
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ namespace Orchard.Users.Services {
|
|||||||
ContactEmail = site.As<RegistrationSettingsPart>().ValidateEmailContactEMail,
|
ContactEmail = site.As<RegistrationSettingsPart>().ValidateEmailContactEMail,
|
||||||
ChallengeUrl = url
|
ChallengeUrl = url
|
||||||
}));
|
}));
|
||||||
|
template.Metadata.Wrappers.Add("Template_User_Wrapper");
|
||||||
|
|
||||||
var payload = new {
|
var payload = new {
|
||||||
Subject = T("Verification E-Mail").Text,
|
Subject = T("Verification E-Mail").Text,
|
||||||
@@ -163,6 +164,7 @@ namespace Orchard.Users.Services {
|
|||||||
User = user,
|
User = user,
|
||||||
LostPasswordUrl = url
|
LostPasswordUrl = url
|
||||||
}));
|
}));
|
||||||
|
template.Metadata.Wrappers.Add("Template_User_Wrapper");
|
||||||
|
|
||||||
var payload = new {
|
var payload = new {
|
||||||
Subject = T("Lost password").Text,
|
Subject = T("Lost password").Text,
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
@* Override this template to alter the email messages sent by the Orchard.Users module *@
|
||||||
|
@Display.PlaceChildContent(Source: Model)
|
||||||
Reference in New Issue
Block a user