Last active
August 29, 2015 14:01
-
-
Save lowedown/7f98ec0b3e3f2341ba21 to your computer and use it in GitHub Desktop.
Globally override Web Forms for Marketers Email Sending settings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net; | |
using Sitecore.Form.Core.Pipelines.ProcessMessage; | |
namespace MyProject.Forms | |
{ | |
/// <summary> | |
/// Overrides Web forms for marketers mail settings through global configuration options. | |
/// </summary> | |
public class ApplySendingSettings | |
{ | |
public string Host | |
{ | |
get { return Sitecore.Configuration.Settings.GetSetting("WFM.Custom.Email.Host", string.Empty); } | |
} | |
public NetworkCredential Credentials | |
{ | |
get | |
{ | |
return new NetworkCredential(Sitecore.Configuration.Settings.GetSetting("WFM.Custom.Email.User", string.Empty), | |
Sitecore.Configuration.Settings.GetSetting("WFM.Custom.Email.Password", | |
string.Empty)); | |
} | |
} | |
public bool EnableSsl | |
{ | |
get | |
{ | |
var setting = Sitecore.Configuration.Settings.GetSetting("WFM.Custom.Email.EnableSSL", string.Empty); | |
if (string.IsNullOrEmpty(setting)) | |
{ | |
return false; | |
} | |
return setting.Equals("true", StringComparison.CurrentCultureIgnoreCase); | |
} | |
} | |
public bool SendAsHtml | |
{ | |
get | |
{ | |
var setting = Sitecore.Configuration.Settings.GetSetting("WFM.Custom.Email.SendAsHtml", string.Empty); | |
if (string.IsNullOrEmpty(setting)) | |
{ | |
return false; | |
} | |
return setting.Equals("true", StringComparison.CurrentCultureIgnoreCase); | |
} | |
} | |
public int Port | |
{ | |
get | |
{ | |
var setting = Sitecore.Configuration.Settings.GetSetting("WFM.Custom.Email.Port", "25"); | |
int port; | |
int.TryParse(setting, out port); | |
return port; | |
} | |
} | |
public string From | |
{ | |
get { return Sitecore.Configuration.Settings.GetSetting("WFM.Custom.Email.From", string.Empty); } | |
} | |
public string Bcc | |
{ | |
get { return Sitecore.Configuration.Settings.GetSetting("WFM.Custom.Email.Bcc", string.Empty); } | |
} | |
public void Process(ProcessMessageArgs args) | |
{ | |
args.Host = Host; | |
args.Credentials = Credentials; | |
args.EnableSsl = EnableSsl; | |
args.Port = Port; | |
args.IsBodyHtml = SendAsHtml; | |
args.From = string.IsNullOrEmpty(From) ? args.From : From; | |
// Add a global BCC | |
if (!string.IsNullOrEmpty(Bcc)) | |
{ | |
if (args.BCC.Length != 0) | |
{ | |
args.BCC.Append(","); | |
} | |
args.BCC.Append(Bcc); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<pipelines> | |
<processMessage> | |
<!-- Custom E-Mail Processor for Web Forms --> | |
<processor type="MyProject.Forms.EMail.ApplySendingSettings, MyProject" method="Process" patch:before="processor[@method='SendEmail']"/> | |
</processMessage> | |
</pipelines> | |
<settings> | |
<!-- Mail Server Host Name / Port --> | |
<setting name="WFM.Custom.Email.Host" value=""/> | |
<setting name="WFM.Custom.Email.Port" value="25"/> | |
<!-- Mail Server login credentials --> | |
<setting name="WFM.Custom.Email.User" value=""/> | |
<setting name="WFM.Custom.Email.Password" value=""/> | |
<setting name="WFM.Custom.Email.EnableSSL" value="false"/> | |
<setting name="WFM.Custom.Email.SendAsHtml" value="true"/> | |
<!-- From address to use unless specified otherwise in save action --> | |
<setting name="WFM.Custom.Email.From" value=""/> | |
<!-- Global BCC address added to every message --> | |
<setting name="WFM.Custom.Email.Bcc" value=""/> | |
</settings> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment