public async Task NotifyOwnerAsync(OwnerNotificationMessage ownerNotificationMessage) { var message = CreateEmailMessage(ownerNotificationMessage); await _sendGridClient .SendEmailAsync(message) .ConfigureAwait(false); }
private SendGridMessage CreateEmailMessage(OwnerNotificationMessage ownerNotificationMessage) { var emailBody = string.Format( _options.EmailBodyTemplate, ownerNotificationMessage.VehicleOwnerInfo.GetFullName(), ownerNotificationMessage.VehicleOwnerInfo.VehicleRegistrationNumber, ownerNotificationMessage.InfractionDate, ownerNotificationMessage.InfractionDistrict, ownerNotificationMessage.TicketNumber ); var subject = string.Format( _options.EmailSubject, ownerNotificationMessage.TicketNumber ); SendGridMessage message = new SendGridMessage { From = new EmailAddress(_options.EmailFromAddress), Subject = subject, }; message.AddTo(ownerNotificationMessage.VehicleOwnerInfo.Email); message.AddContent("text/html", emailBody); foreach (var attachment in ownerNotificationMessage.Attachments) { message.AddAttachment( new Attachment { Content = attachment.Content, Type = attachment.ContentType, Filename = attachment.Name } ); } return(message); }