private MimeMessage CreateEmailMessage(ServiceProviderMessage message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress(_configuration.From)); emailMessage.To.AddRange(message.To); emailMessage.Subject = "Service Provider Inquiry"; var bodyBuilder = new BodyBuilder() { HtmlBody = string.Format($"<h2>Name: {message.Name}</h2>\n<br/>" + $"<p>Email: {message.Email}</p>\n<br/>" + $"<p>Phone Number: {message.PhoneNumber}</p>\n<br/>" + $"<p>Company Name: {message.CompanyName}</p>\n<br/>" + $"<p>Website: {message.Website}</p>\n<br/>" + $"<p>involvement: {message.Involvement}</p>\n<br/>" + $"<p>{message.Message}</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 //Service Provider Message public async Task SendMailAsync(ServiceProviderMessage message) { var emailMessage = CreateEmailMessage(message); await SendAsync(emailMessage); }