private MailMessage MailMsgToMailMessage(MailMsg msg) { var mailMessage = new MailMessage(); mailMessage.From = new MailAddress(_settingsService.GetSettings <string>("SystemEmailAddress"), _settingsService.GetSettings <string>("SystemEmailSenderName")); var receivers = msg.Receiver.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string receiver in receivers) { mailMessage.To.Add(new MailAddress(receiver)); } mailMessage.Subject = msg.Subject; mailMessage.IsBodyHtml = true; string body = _razorEngineService.RenderEmailMessage("TextMessage", msg.Body); mailMessage.Body = body; if (!String.IsNullOrWhiteSpace(msg.BccReceiver)) { mailMessage.Bcc.Add(new MailAddress(msg.BccReceiver)); } if (msg.AttachIds != null && msg.AttachIds.Any()) { AttachFiles(mailMessage, msg.AttachIds); } return(mailMessage); }
private void SendOrderToInternalEmail(Order order, Client client) { string htmlString = _razorService.RenderEmailMessage("ShopOrderAdmin", new ShopOrderEmail { Order = order, Client = client }); var msg = new MailMsg() { Receiver = _settingsService.GetSettings <string>("OrderEmailAddress"), Body = htmlString, Subject = "Заказ в интернет-магазине: " + DateTime.UtcNow.ApplySiteTimezone() }; _mailService.Send(msg); }
public void SendAnswerToAuthor(int questionId) { var dataRec = _questionGateway.SelectOne(questionId); if (string.IsNullOrEmpty(dataRec.AuthorEmail)) { throw new ArgumentException("Empty email", nameof(dataRec.AuthorEmail)); } var msg = new MailMsg(); msg.Subject = "Ответ на вопрос"; msg.Receiver = dataRec.AuthorEmail; msg.Body = _razorEngineService.RenderEmailMessage("FAQAnswerMessage", Mapper.Map <Question>(dataRec)); _mailService.Send(msg); dataRec.AnswerSentToAuthor = true; _questionGateway.Update(dataRec); }