예제 #1
0
        private MimeMessage CreateEmailMessage(ContactUsMessage message)
        {
            var emailMessage = new MimeMessage();

            emailMessage.From.Add(new MailboxAddress(_configuration.From));
            emailMessage.To.AddRange(message.To);
            emailMessage.Subject = message.Subject;


            var bodyBuilder = new BodyBuilder()
            {
                HtmlBody = string.Format($"<h2>Hi, I'm {message.Name}</h2>\n<br/>" +
                                         $"<p>Email: {message.Email}</p>\n<br/>" +
                                         $"<p>{message.Content}</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);
        }
예제 #2
0
        //Contact Us Mail Settings
        public async Task SendMailAsync(ContactUsMessage message)
        {
            var emailMessage = CreateEmailMessage(message);

            await SendAsync(emailMessage);
        }