-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v15/dev' into v15/feature/staticassets-msbuild-conditions
- Loading branch information
Showing
5 changed files
with
101 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
50 changes: 50 additions & 0 deletions
50
src/Umbraco.Infrastructure/Mail/BasicSmtpEmailSenderClient.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Net.Mail; | ||
using Microsoft.Extensions.Options; | ||
using Umbraco.Cms.Core.Configuration.Models; | ||
using Umbraco.Cms.Core.Models.Email; | ||
using Umbraco.Cms.Infrastructure.Extensions; | ||
using Umbraco.Cms.Infrastructure.Mail.Interfaces; | ||
using SecureSocketOptions = MailKit.Security.SecureSocketOptions; | ||
using SmtpClient = MailKit.Net.Smtp.SmtpClient; | ||
|
||
namespace Umbraco.Cms.Infrastructure.Mail | ||
{ | ||
/// <summary> | ||
/// A basic SMTP email sender client using MailKits SMTP client. | ||
/// </summary> | ||
public class BasicSmtpEmailSenderClient : IEmailSenderClient | ||
{ | ||
private readonly GlobalSettings _globalSettings; | ||
public BasicSmtpEmailSenderClient(IOptionsMonitor<GlobalSettings> globalSettings) | ||
{ | ||
_globalSettings = globalSettings.CurrentValue; | ||
} | ||
|
||
public async Task SendAsync(EmailMessage message) | ||
{ | ||
using var client = new SmtpClient(); | ||
|
||
await client.ConnectAsync( | ||
_globalSettings.Smtp!.Host, | ||
_globalSettings.Smtp.Port, | ||
(SecureSocketOptions)(int)_globalSettings.Smtp.SecureSocketOptions); | ||
|
||
if (!string.IsNullOrWhiteSpace(_globalSettings.Smtp.Username) && | ||
!string.IsNullOrWhiteSpace(_globalSettings.Smtp.Password)) | ||
{ | ||
await client.AuthenticateAsync(_globalSettings.Smtp.Username, _globalSettings.Smtp.Password); | ||
} | ||
|
||
var mimeMessage = message.ToMimeMessage(_globalSettings.Smtp!.From); | ||
|
||
if (_globalSettings.Smtp.DeliveryMethod == SmtpDeliveryMethod.Network) | ||
{ | ||
await client.SendAsync(mimeMessage); | ||
} | ||
else | ||
{ | ||
client.Send(mimeMessage); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
17 changes: 17 additions & 0 deletions
17
src/Umbraco.Infrastructure/Mail/Interfaces/IEmailSenderClient.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Umbraco.Cms.Core.Models.Email; | ||
|
||
namespace Umbraco.Cms.Infrastructure.Mail.Interfaces | ||
{ | ||
/// <summary> | ||
/// Client for sending an email from a MimeMessage | ||
/// </summary> | ||
public interface IEmailSenderClient | ||
{ | ||
/// <summary> | ||
/// Sends the email message | ||
/// </summary> | ||
/// <param name="message"></param> | ||
/// <returns></returns> | ||
public Task SendAsync(EmailMessage message); | ||
} | ||
} |
This file contains 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