mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Adding email template wrappers
This commit is contained in:
parent
87a9b8d72d
commit
50d759ad4a
@ -79,6 +79,7 @@
|
||||
<Compile Include="Rules\MailActions.cs" />
|
||||
<Compile Include="Rules\MailForms.cs" />
|
||||
<Compile Include="Services\DefaultEmailMessageChannelSelector.cs" />
|
||||
<Compile Include="Services\ISmtpChannel.cs" />
|
||||
<Compile Include="Services\SmtpMessageChannel.cs" />
|
||||
<Compile Include="Services\EmailMessageEventHandler.cs" />
|
||||
<Compile Include="Services\EmailMessagingChannel.cs" />
|
||||
@ -129,6 +130,9 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Activity-SendEmail.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Template.Smtp.Wrapper.cshtml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
@ -1,21 +1,21 @@
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Email.Models;
|
||||
using Orchard.Messaging.Services;
|
||||
using Orchard.Messaging.Services;
|
||||
|
||||
namespace Orchard.Email.Services {
|
||||
public class DefaultEmailMessageChannelSelector : Component, IMessageChannelSelector {
|
||||
private readonly IOrchardServices _services;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
public const string ChannelName = "Email";
|
||||
|
||||
public DefaultEmailMessageChannelSelector(IOrchardServices services) {
|
||||
_services = services;
|
||||
public DefaultEmailMessageChannelSelector(IWorkContextAccessor workContextAccessor) {
|
||||
_workContextAccessor = workContextAccessor;
|
||||
}
|
||||
|
||||
|
||||
public MessageChannelSelectorResult GetChannel(string messageType, object payload) {
|
||||
if (messageType == "Email") {
|
||||
var workContext = _workContextAccessor.GetContext();
|
||||
var channel = workContext.Resolve<ISmtpChannel>();
|
||||
return new MessageChannelSelectorResult {
|
||||
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.Net;
|
||||
using System.Net.Mail;
|
||||
using System.Web.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Email.Models;
|
||||
using Orchard.Messaging.Services;
|
||||
|
||||
namespace Orchard.Email.Services {
|
||||
public class SmtpMessageChannel : Component, IMessageChannel, IDisposable {
|
||||
public class SmtpMessageChannel : Component, ISmtpChannel, IDisposable {
|
||||
private readonly SmtpSettingsPart _smtpSettings;
|
||||
private readonly IShapeFactory _shapeFactory;
|
||||
private readonly IShapeDisplay _shapeDisplay;
|
||||
private readonly Lazy<SmtpClient> _smtpClientField;
|
||||
public static readonly string MessageType = "Email";
|
||||
|
||||
public SmtpMessageChannel(SmtpSettingsPart smtpSettings) {
|
||||
_smtpSettings = smtpSettings;
|
||||
public SmtpMessageChannel(
|
||||
IOrchardServices orchardServices,
|
||||
IShapeFactory shapeFactory,
|
||||
IShapeDisplay shapeDisplay) {
|
||||
_shapeFactory = shapeFactory;
|
||||
_shapeDisplay = shapeDisplay;
|
||||
|
||||
_smtpSettings = orchardServices.WorkContext.CurrentSite.As<SmtpSettingsPart>();
|
||||
_smtpClientField = new Lazy<SmtpClient>(CreateSmtpClient);
|
||||
}
|
||||
|
||||
@ -26,6 +36,8 @@ namespace Orchard.Email.Services {
|
||||
}
|
||||
|
||||
public void Process(string payload) {
|
||||
|
||||
|
||||
if (!_smtpSettings.IsValid()) {
|
||||
return;
|
||||
}
|
||||
@ -40,11 +52,16 @@ namespace Orchard.Email.Services {
|
||||
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 {
|
||||
From = new MailAddress(_smtpSettings.Address),
|
||||
Subject = emailMessage.Subject,
|
||||
Body = emailMessage.Body,
|
||||
IsBodyHtml = emailMessage.Body != null && emailMessage.Body.Contains("<") && emailMessage.Body.Contains(">")
|
||||
Body = _shapeDisplay.Display(template),
|
||||
IsBodyHtml = true
|
||||
};
|
||||
|
||||
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>
|
||||
<Content Include="Views\Template.User.LostPassword.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Template.User.Wrapper.cshtml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
@ -109,6 +109,8 @@ namespace Orchard.Users.Services {
|
||||
var recipient = GetUser(userName);
|
||||
if (recipient != null) {
|
||||
var template = _shapeFactory.Create("Template_User_Moderated", Arguments.From(createUserParams));
|
||||
template.Metadata.Wrappers.Add("Template_User_Wrapper");
|
||||
|
||||
var payload = new {
|
||||
Subject = T("New account").Text,
|
||||
Body = _shapeDisplay.Display(template),
|
||||
|
@ -140,6 +140,7 @@ namespace Orchard.Users.Services {
|
||||
ContactEmail = site.As<RegistrationSettingsPart>().ValidateEmailContactEMail,
|
||||
ChallengeUrl = url
|
||||
}));
|
||||
template.Metadata.Wrappers.Add("Template_User_Wrapper");
|
||||
|
||||
var payload = new {
|
||||
Subject = T("Verification E-Mail").Text,
|
||||
@ -163,6 +164,7 @@ namespace Orchard.Users.Services {
|
||||
User = user,
|
||||
LostPasswordUrl = url
|
||||
}));
|
||||
template.Metadata.Wrappers.Add("Template_User_Wrapper");
|
||||
|
||||
var payload = new {
|
||||
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)
|
Loading…
Reference in New Issue
Block a user