private MimeMessage CreateEmailMessage(BrokerMessage message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress(_configuration.From)); emailMessage.To.AddRange(message.To); emailMessage.Subject = "Broker Inquiry"; var bodyBuilder = new BodyBuilder() { HtmlBody = string.Format($"<h2>Hi, I'm {message.Name}</h2>\n<br/>" + $"<p>Email: {message.Email}</p>\n<br/>" + $"<p>Number: {message.Number}</p>\n<br/>" + $"<p>Service Provider:{message.ServiceProvider}</p>\n<br/>" + "Thank you") }; if (message.AttachmentFiles != null && message.AttachmentFiles.Any()) { byte[] fileBytes; foreach (var file in message.AttachmentFiles) { using (var ms = new MemoryStream()) { file.CopyTo(ms); fileBytes = ms.ToArray(); } bodyBuilder.Attachments.Add(file.FileName, fileBytes, ContentType.Parse(file.ContentType)); } } emailMessage.Body = bodyBuilder.ToMessageBody(); return(emailMessage); }
//End of Code //Code for Broker Page public async Task SendMailAsync(BrokerMessage message) { var emailMessage = CreateEmailMessage(message); await SendAsync(emailMessage); }