Created
April 11, 2018 08:30
-
-
Save iyhammad/a947bf12893cf1670422e166ed79bc03 to your computer and use it in GitHub Desktop.
CustomMailKitSmtpBuilder --- Compatible with Office 365
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
using Abp.MailKit; | |
using Abp.Net.Mail.Smtp; | |
using MailKit.Net.Smtp; | |
using MailKit.Security; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace SystemX.Web.MailBauilder | |
{ | |
//This is to be compatible with Office 365 Mails | |
public class CustomMailKitSmtpBuilder : DefaultMailKitSmtpBuilder | |
{ | |
private ISmtpEmailSenderConfiguration _smtpEmailSenderConfiguration; | |
public CustomMailKitSmtpBuilder(ISmtpEmailSenderConfiguration smtpEmailSenderConfiguration) | |
: base(smtpEmailSenderConfiguration) | |
{ | |
this._smtpEmailSenderConfiguration = smtpEmailSenderConfiguration; | |
} | |
protected override void ConfigureClient(SmtpClient client) | |
{ | |
client.Connect( | |
_smtpEmailSenderConfiguration.Host, | |
_smtpEmailSenderConfiguration.Port, | |
SecureSocketOptions.StartTlsWhenAvailable | |
); | |
if (_smtpEmailSenderConfiguration.UseDefaultCredentials) | |
{ | |
return; | |
} | |
client.Authenticate( | |
_smtpEmailSenderConfiguration.UserName, | |
_smtpEmailSenderConfiguration.Password | |
); | |
} | |
} | |
} |
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
public class WebModule : AbpModule | |
{ | |
public override void PreInitialize() | |
{ | |
//Other configuration goes here | |
Configuration.ReplaceService<IMailKitSmtpBuilder, CustomMailKitSmtpBuilder>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment