...
 
Commits (2)
......@@ -52,14 +52,30 @@ namespace Breeze.CMS.Services {
msg.Body = ProcessTemplate(culture, templateKey, context, templateText, bag);
return SendAsync(msg);
}
public virtual Task SendAsync(MailMessage msg) {
using (SmtpClient client = new SmtpClient()) {
_log.InfoFormat("Email \"{0}\" sent to [{1}]", msg.Subject, String.Join(";", msg.To.Select(x => x.Address)));
return client.SendMailAsync(msg);
}
}
Task IIdentityMessageService.SendAsync(IdentityMessage message) {
//Changed by Zubashenko Ruslan.
//The client is disposed before sending the email.
//public virtual Task SendAsync(MailMessage msg) {
// using (SmtpClient client = new SmtpClient()) {
// _log.InfoFormat("Email \"{0}\" sent to [{1}]", msg.Subject, String.Join(";", msg.To.Select(x => x.Address)));
// return client.SendMailAsync(msg);
// }
//}
public virtual Task SendAsync(MailMessage msg) {
SmtpClient client = new SmtpClient();
client.SendCompleted += delegate (object sender, System.ComponentModel.AsyncCompletedEventArgs args) {
(sender as SmtpClient)?.Dispose();
if (args.Error == null)
_log.InfoFormat("Email \"{0}\" sent to [{1}]", msg.Subject, String.Join(";", msg.To.Select(x => x.Address)));
else {
_log.Error($"Error sending email \"{msg.Subject}\" to [{String.Join(";", msg.To.Select(x => x.Address))}]", args.Error);
}
};
return client.SendMailAsync(msg);
}
Task IIdentityMessageService.SendAsync(IdentityMessage message) {
using (MailMessage msg = new MailMessage()) {
msg.To.Add(new MailAddress(message.Destination));
msg.Subject = message.Subject;
......