Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement email provider #3968

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Provide any additional context that may be helpful in understanding and/or resol
Please add X in at least one of the boxes as appropriate. In order for an issue to be accepted, a developer needs to be able to reproduce the issue on a currently supported version. If you are looking for a workaround for an issue with an older version, please visit the forums at https://dnncommunity.org/forums
-->
* [ ] 10.00.00 alpha build
* [ ] 09.06.02 release candidate
* [ ] 09.06.01 latest supported release
* [ ] 09.07.00 release candidate
* [ ] 09.06.02 latest supported release

## Affected browser
<!--
Expand Down
2 changes: 1 addition & 1 deletion Build/Symbols/DotNetNuke_Symbols.dnn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="DotNetNuke_Symbols" type="Library" version="09.06.02" >
<package name="DotNetNuke_Symbols" type="Library" version="09.07.00" >
<friendlyName>DNN Platform Symbols</friendlyName>
<description>This package contains Debug Symbols and Intellisense files for DNN Platform.</description>
<owner>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="DotNetNuke.Console" type="Module" version="09.06.02">
<package name="DotNetNuke.Console" type="Module" version="09.07.00">
<friendlyName>Console</friendlyName>
<description>Display children pages as icon links for navigation.</description>
<iconFile>~/DesktopModules/Admin/Console/console.png</iconFile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="DotNetNuke.Module Creator" type="Module" version="09.06.02">
<package name="DotNetNuke.Module Creator" type="Module" version="09.07.00">
<friendlyName>Module Creator</friendlyName>
<description>Development of modules.</description>
<iconFile>~/Icons/Sigma/ModuleCreator_32x32.png</iconFile>
Expand Down
2 changes: 1 addition & 1 deletion DNN Platform/Components/Telerik/DotNetNuke.Telerik.Web.dnn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="DotNetNuke.Telerik.Web" type="Library" isSystem="true" version="09.06.02">
<package name="DotNetNuke.Telerik.Web" type="Library" isSystem="true" version="09.07.00">
<friendlyName>DotNetNuke Telerik Web Components</friendlyName>
<description>Provides Telerik Components for DotNetNuke.</description>
<dependencies/>
Expand Down
2 changes: 1 addition & 1 deletion DNN Platform/Connectors/Azure/AzureConnector.dnn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="Dnn.AzureConnector" type="Connector" isSystem="false" version="09.06.02">
<package name="Dnn.AzureConnector" type="Connector" isSystem="false" version="09.07.00">
<friendlyName>Dnn Azure Connector</friendlyName>
<description>The Azure Connector allows you to integrate Azure as your commenting solution with the Publisher module.</description>
<iconFile>~/DesktopModules/Connectors/Azure/Images/icon-azure-32px.png</iconFile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="DNN.Connectors.GoogleAnalytics" type="Connector" isSystem="false" version="09.06.02">
<package name="DNN.Connectors.GoogleAnalytics" type="Connector" isSystem="false" version="09.07.00">
<friendlyName>Google Analytics Connector</friendlyName>
<description>Configure your sites Google Analytics settings.</description>
<iconFile>~/DesktopModules/Connectors/GoogleAnalytics/Images/GoogleAnalytics_32X32_Standard.png</iconFile>
Expand Down
2 changes: 1 addition & 1 deletion DNN Platform/Dnn.AuthServices.Jwt/Dnn.Jwt.dnn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="DNNJWT" type="Provider" version="09.06.02">
<package name="DNNJWT" type="Provider" version="09.07.00">
<friendlyName>DNN JWT Auth Handler</friendlyName>
<description>DNN Json Web Token Authentication (JWT) library for cookie-less Mobile authentication clients</description>
<dependencies/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="DotNetNuke.Web.Deprecated" type="Library" isSystem="true" version="09.06.02">
<package name="DotNetNuke.Web.Deprecated" type="Library" isSystem="true" version="09.07.00">
<friendlyName>DNN Deprecated Web Controls Library</friendlyName>
<description>DNN Deprecated Web Controls library for legacy Telerik depepndency</description>
<dependencies/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace DotNetNuke.Web.Common.Internal
using DotNetNuke.Services.Search.Internals;
using DotNetNuke.Services.Sitemap;
using DotNetNuke.Services.Tokens;
using DotNetNuke.Services.Mail;
using DotNetNuke.Services.Url.FriendlyUrl;

/// <summary>
Expand Down Expand Up @@ -164,6 +165,7 @@ private void Application_Start(object sender, EventArgs eventArgs)
ComponentFactory.InstallComponents(new ProviderInstaller("clientcapability", typeof(ClientCapabilityProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("cryptography", typeof(CryptographyProvider), typeof(FipsCompilanceCryptographyProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("tokens", typeof(TokenProvider)));
ComponentFactory.InstallComponents(new ProviderInstaller("mail", typeof(MailProvider)));

Logger.InfoFormat("Application Started ({0})", Globals.ElapsedSinceAppStart); // just to start the timer
DotNetNukeShutdownOverload.InitializeFcnSettings();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="DotNetNuke.ClientAPI" type="Library" version="09.06.02" >
<package name="DotNetNuke.ClientAPI" type="Library" version="09.07.00" >
<friendlyName>DotNetNuke ClientAPI</friendlyName>
<description>The DotNetNuke Client API is composed of both server-side and client-side code that works together to enable a simple and reliable interface for the developer to provide a rich client-side experience.</description>
<dependencies/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="DotNetNuke.Website.Deprecated" type="Library" isSystem="true" version="09.06.02">
<package name="DotNetNuke.Website.Deprecated" type="Library" isSystem="true" version="09.07.00">
<friendlyName>DNN Deprecated Website Codebehind files</friendlyName>
<description>DNN Deprecated Website Codebehind files for backward compability.</description>
<dependencies/>
Expand Down
4 changes: 4 additions & 0 deletions DNN Platform/Library/DotNetNuke.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,10 @@
<Compile Include="Services\Localization\Persian\PersianCalendar.cs" />
<Compile Include="Services\Localization\Persian\PersianController.cs" />
<Compile Include="Services\Log\EventLog\ILogController.cs" />
<Compile Include="Services\Mail\CoreMailProvider.cs" />
<Compile Include="Services\Mail\SMTPInfo.cs" />
<Compile Include="Services\Mail\MailInfo.cs" />
<Compile Include="Services\Mail\MailProvider.cs" />
<Compile Include="Services\OutputCache\Providers\DatabaseProvider.cs" />
<Compile Include="Services\OutputCache\Providers\DatabaseResponseFilter.cs" />
<Compile Include="Services\OutputCache\Providers\FileProvider.cs" />
Expand Down
216 changes: 216 additions & 0 deletions DNN Platform/Library/Services/Mail/CoreMailProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Host;
using DotNetNuke.Entities.Portals;
using System;
using System.Net;
using System.Net.Mail;
using System.Text.RegularExpressions;
using Localize = DotNetNuke.Services.Localization.Localization;
namespace DotNetNuke.Services.Mail
{
public class CoreMailProvider : MailProvider
{
private static readonly Regex SmtpServerRegex = new Regex("^[^:]+(:[0-9]{1,5})?$", RegexOptions.Compiled);
private static string ConvertToText(string sHTML)
{
var formattedHtml = HtmlUtils.FormatText(sHTML, true);
var styleLessHtml = HtmlUtils.RemoveInlineStyle(formattedHtml);
return HtmlUtils.StripTags(styleLessHtml, true);
}
public override string SendMail(MailInfo mailInfo, SMTPInfo smtpInfo = null)
{
// validate smtp server
if (smtpInfo == null || string.IsNullOrEmpty(smtpInfo.Server))
{
if (string.IsNullOrWhiteSpace(Host.SMTPServer))
{
return "SMTP Server not configured";
}

smtpInfo = new SMTPInfo()
{
Server = Host.SMTPServer,
Authentication = Host.SMTPAuthentication,
Username = Host.SMTPUsername,
Password = Host.SMTPPassword,
EnableSSL = Host.EnableSMTPSSL,
};
}

// translate semi-colon delimiters to commas as ASP.NET 2.0 does not support semi-colons
if (!string.IsNullOrEmpty(mailInfo.To))
{
mailInfo.To = mailInfo.To.Replace(";", ",");
}

if (!string.IsNullOrEmpty(mailInfo.CC))
{
mailInfo.To = mailInfo.To.Replace(";", ",");
}

if (!string.IsNullOrEmpty(mailInfo.BCC))
{
mailInfo.To = mailInfo.To.Replace(";", ",");
}

string retValue = string.Empty;

MailMessage mailMessage = new MailMessage(mailInfo.From, mailInfo.To);

if (!string.IsNullOrEmpty(mailInfo.Sender))
{
mailMessage.Sender = new MailAddress(mailInfo.Sender);
}

mailMessage.Priority = (System.Net.Mail.MailPriority)mailInfo.Priority;
mailMessage.IsBodyHtml = mailInfo.BodyFormat == MailFormat.Html;

// Only modify senderAdress if smtpAuthentication is enabled
// Can be "0", empty or Null - anonymous, "1" - basic, "2" - NTLM.
if (smtpInfo.Authentication == "1" || smtpInfo.Authentication == "2")
{
// if the senderAddress is the email address of the Host then switch it smtpUsername if different
// if display name of senderAddress is empty, then use Host.HostTitle for it
if (mailMessage.Sender != null)
{
var senderAddress = mailInfo.Sender;
var senderDisplayName = mailInfo.FromName;
var needUpdateSender = false;
if (smtpInfo.Username.Contains("@") && senderAddress == Host.HostEmail &&
!senderAddress.Equals(smtpInfo.Username, StringComparison.InvariantCultureIgnoreCase))
{
senderAddress = smtpInfo.Username;
needUpdateSender = true;
}

if (string.IsNullOrEmpty(senderDisplayName))
{
senderDisplayName = Host.SMTPPortalEnabled ? PortalSettings.Current.PortalName : Host.HostTitle;
needUpdateSender = true;
}

if (needUpdateSender)
{
mailMessage.Sender = new MailAddress(senderAddress, senderDisplayName);
}
}
else if (smtpInfo.Username.Contains("@"))
{
mailMessage.Sender = new MailAddress(smtpInfo.Username, Host.SMTPPortalEnabled ? PortalSettings.Current.PortalName : Host.HostTitle);
}
}

//attachments
if (mailInfo.Attachments != null)
{
foreach (var attachment in mailInfo.Attachments)
{
mailMessage.Attachments.Add(attachment);
}
}

// message
mailMessage.SubjectEncoding = mailInfo.BodyEncoding;
mailMessage.Subject = HtmlUtils.StripWhiteSpace(mailInfo.Subject, true);
mailMessage.BodyEncoding = mailInfo.BodyEncoding;

// added support for multipart html messages
// add text part as alternate view
var PlainView = AlternateView.CreateAlternateViewFromString(ConvertToText(mailInfo.Body), null, "text/plain");
mailMessage.AlternateViews.Add(PlainView);
if (mailMessage.IsBodyHtml)
{
var HTMLView = AlternateView.CreateAlternateViewFromString(mailInfo.Body, null, "text/html");
mailMessage.AlternateViews.Add(HTMLView);
}

smtpInfo.Server = smtpInfo.Server.Trim();
if (SmtpServerRegex.IsMatch(smtpInfo.Server))
{
try
{
// to workaround problem in 4.0 need to specify host name
using (var smtpClient = new SmtpClient())
{
var smtpHostParts = smtpInfo.Server.Split(':');
smtpClient.Host = smtpHostParts[0];
if (smtpHostParts.Length > 1)
{
// port is guaranteed to be of max 5 digits numeric by the RegEx check
var port = Convert.ToInt32(smtpHostParts[1]);
if (port < 1 || port > 65535)
{
return Localize.GetString("SmtpInvalidPort");
}

smtpClient.Port = port;
}

// else the port defaults to 25 by .NET when not set
smtpClient.ServicePoint.MaxIdleTime = Host.SMTPMaxIdleTime;
smtpClient.ServicePoint.ConnectionLimit = Host.SMTPConnectionLimit;

switch (smtpInfo.Authentication)
{
case "":
case "0": // anonymous
break;
case "1": // basic
if (!string.IsNullOrEmpty(smtpInfo.Username) && !string.IsNullOrEmpty(smtpInfo.Password))
{
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(smtpInfo.Username, smtpInfo.Password);
}

break;
case "2": // NTLM
smtpClient.UseDefaultCredentials = true;
break;
}

smtpClient.EnableSsl = smtpInfo.EnableSSL;
smtpClient.Send(mailMessage);
smtpClient.Dispose();
}
}
catch (Exception exc)
{
var exc2 = exc as SmtpFailedRecipientException;
if (exc2 != null)
{
retValue = string.Format(Localize.GetString("FailedRecipient"), exc2.FailedRecipient) + " ";
}
else if (exc is SmtpException)
{
retValue = Localize.GetString("SMTPConfigurationProblem") + " ";
}

// mail configuration problem
if (exc.InnerException != null)
{
retValue += string.Concat(exc.Message, Environment.NewLine, exc.InnerException.Message);
Exceptions.Exceptions.LogException(exc.InnerException);
}
else
{
retValue += exc.Message;
Exceptions.Exceptions.LogException(exc);
}
}
finally
{
mailMessage.Dispose();
}
}
else
{
retValue = Localize.GetString("SMTPConfigurationProblem");
}

return retValue;
}
}
}
Loading