logic added
This commit is contained in:
@@ -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>();
|
||||
|
||||
Reference in New Issue
Block a user