// This is an engine because I plan to add scheduled processes to this, and // the accessor should only deal with sending the email itself public async Task SendEmail(EmailDto email) { var emailMessage = new MailMessage() { From = new MailAddress(email.FromAddress), Subject = email.Subject, Body = email.TextContent, }; if (email?.ToAddresses?.Count() > 0) { emailMessage.To.Add(string.Join(',', email.ToAddresses)); } if (email?.CcAddresses?.Count() > 0) { emailMessage.CC.Add(string.Join(',', email.CcAddresses)); } if (email?.BccAddresses?.Count() > 0) { emailMessage.Bcc.Add(string.Join(',', email.BccAddresses)); } if (!string.IsNullOrWhiteSpace(email.HtmlContent)) { emailMessage.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(email.HtmlContent, new ContentType("text/plain"))); } await _emailAccessor.SendEmail(emailMessage); }
private async Task SendResultEmail(ExportRequestDto dto, byte[] zip) { await _emailAccessor.SendEmail(new EmailMessageDto { To = dto.Email, From = "*****@*****.**", //TODO pull from settings Subject = $"Export Result {dto.RequestId}", Body = $"Request Id: '{dto.RequestId}' is complete! <br />Check this message for an attatchment.", FileName = $"Export-{DateTime.Now:yyyy-MM-dd}.zip", AttatchmentMime = "application/zip", File = zip }); }