logic added

This commit is contained in:
2021-02-04 22:45:41 +01:00
parent e5098c02d9
commit bf57e3a983
11 changed files with 150 additions and 28 deletions

View File

@@ -39,6 +39,34 @@ namespace Massmailer.Shared.Logic
return message;
}
public async Task SendMailsAsync(MassmailerProject project)
{
try
{
await this.smtpClient.ConnectAsync(this.smtpSettings.Server, this.smtpSettings.Port, this.smtpSettings.UseSsl);
await this.smtpClient.AuthenticateAsync(this.smtpSettings.Username, this.smtpSettings.Password);
foreach (var recipient in project.Recipients)
{
await this.CheckForWaitTime();
var message = this.CreateMessage(recipient.Address, project.Subject, project.Body);
await this.smtpClient.SendAsync(message);
this.lastMailSent = DateTime.Now;
recipient.IsSent = true;
recipient.SentDate = this.lastMailSent;
this.hub.Publish<MailSentEvent>(new MailSentEvent(message.To[0].ToString(), this.lastMailSent));
}
await this.smtpClient.DisconnectAsync(true);
}
catch (Exception ex)
{
throw new InvalidOperationException("Something went wrong while sending many mails", ex);
}
}
public List<MimeMessage> CreateMessages(List<string> recipients, string subject, string body)
{
var result = new List<MimeMessage>();