public void DisplaySelectForm([Comments("Configuration details for the form.")] MessageTemplateParameters setting, [ListEditorControl(ListControlType.Connectors)] ICollection <ConnectorParameters> buttons) { MessageTemplateView view = this.mapper.Map <MessageTemplateView>(setting); this.screenData.ScreenSettings = new ScreenSettings <MessageTemplateView> ( view, mapper.Map <IEnumerable <ConnectorParameters>, IEnumerable <CommandButtonView> >(buttons), ViewType.Select, new MenuItem { Text = view.Message, Icon = view.Icon } ); }
private async Task <Boolean> SendMail(MessageTemplateView template, Notification notification) { var tranStarted = false; try { var smtpServer = new SmtpClient(notification.SMTP.SMTPserver); if (!string.IsNullOrEmpty(notification.SMTP.MailHost)) { smtpServer.Host = notification.SMTP.MailHost; } smtpServer.Port = Convert.ToInt32(notification.SMTP.MailPort); smtpServer.UseDefaultCredentials = false; smtpServer.Credentials = new System.Net.NetworkCredential(notification.SMTP.MailFrom, notification.SMTP.Password); smtpServer.EnableSsl = true; template.From = notification.SMTP.MailFrom; var mail = GetMailDetail(template, notification.SMTP); await smtpServer.SendMailAsync(mail); _unitOfWork.Begin(); tranStarted = true; _emailLog.AddEMailLog(mail, template.NotificationQueue); await _unitOfWork.SaveAsync(); _unitOfWork.Commit(); return(true); } catch (Exception) { //queue.RetryCount++; if (tranStarted) { _unitOfWork.Rollback(); } //queue.Description = ex.ToString(); //queue.Status = NotificationSentStatus.Failed; //_queue.Update(queue); await _unitOfWork.SaveAsync(); throw; } }
private MessageTemplateView GetMessageTemplateView(string shortString, MessageTemplateView view) { view.Selection = shortString; return(view); }
private MailMessage GetMailDetail(MessageTemplateView emailMessage, SMTPConfiguration sMTP) { MailMessage mail = new MailMessage(); mail.From = new MailAddress(emailMessage.From); foreach (string address in emailMessage.To) { if (!string.IsNullOrEmpty(address) && !string.IsNullOrWhiteSpace(address)) { mail.To.Add(new MailAddress(address)); } } if (emailMessage.CC != null) { foreach (string address in emailMessage.CC) { if (!string.IsNullOrEmpty(address) && !string.IsNullOrWhiteSpace(address)) { mail.CC.Add(new MailAddress(address)); } } } if (sMTP.DefaultCC != null) { var defaultCC = sMTP.DefaultCC.Split(';'); if (defaultCC == null || !defaultCC.Any()) { defaultCC = sMTP.DefaultCC.Split(','); } foreach (string address in defaultCC) { if (!string.IsNullOrEmpty(address) && !string.IsNullOrWhiteSpace(address)) { mail.CC.Add(new MailAddress(address)); } } } if (emailMessage.BCC != null) { foreach (string address in emailMessage.BCC) { if (!string.IsNullOrEmpty(address) && !string.IsNullOrWhiteSpace(address)) { mail.Bcc.Add(new MailAddress(address)); } } } if (sMTP.DefaultBCC != null) { var defaultCC = sMTP.DefaultBCC.Split(';'); if (defaultCC == null || !defaultCC.Any()) { defaultCC = sMTP.DefaultBCC.Split(','); } foreach (string address in defaultCC) { if (!string.IsNullOrEmpty(address) && !string.IsNullOrWhiteSpace(address)) { mail.Bcc.Add(new MailAddress(address)); } } } mail.Subject = emailMessage.Subject; mail.Body = emailMessage.MessageBody; mail.IsBodyHtml = true; if (!mail.IsBodyHtml) { mail.Body = mail.Body.Replace("\r\n", "\r"); mail.Body = mail.Body.Replace("\r", "\r\n"); } return(mail); }