public static INotifier GetInstance(String tenantId, IAuthenticatedWho authenticatedWho, List <EngineValueAPI> configurationValues, String codeReference) { INotifier notifier = null; String email = ""; if (configurationValues != null && configurationValues.Count > 0) { email = ValueUtils.GetContentValue(SalesforceServiceSingleton.SERVICE_VALUE_ADMIN_EMAIL, configurationValues, false); } if (String.IsNullOrEmpty(authenticatedWho.Email) == true) { // TODO: This is a hack for the notification as we only use the email authenticatedWho.Email = email; } // Create the notifier for the caller notifier = new EmailNotifier(authenticatedWho); notifier.Reason = codeReference; return(notifier); }
private void SendNotificationsInSeparateThread(EmailNotifier emailNotifier) { NetworkCredential networkCredentials = null; MailMessage mailMessage = null; SmtpClient smtpClient = null; try { // Create the main email message mailMessage = new MailMessage(); mailMessage.To.Add(new MailAddress( this.ReceivingAuthenticatedWho.Email, this.ReceivingAuthenticatedWho.FirstName + " " + this.ReceivingAuthenticatedWho.LastName )); mailMessage.From = new MailAddress( ConfigurationManager.AppSettings.Get("ManyWho.SendAlertFromEmail"), ConfigurationManager.AppSettings.Get("ManyWho.SendAlertFromEmail") ); // We apply the "reason" as the subject mailMessage.Subject = emailNotifier.Reason; // Go through each of the notifications and apply them to the mail alternative views foreach (NotificationMessage notificationMessage in this.NotificationMessages) { // Check to see if we have any log entries to add to the notification if (this.LogEntries != null && this.LogEntries.Count > 0) { foreach (String logEntry in this.LogEntries) { // Check the media type to see how best to render the log entries if (notificationMessage.MediaType.Equals(NotificationUtils.MEDIA_TYPE_HTML, StringComparison.OrdinalIgnoreCase) == true) { notificationMessage.Message += logEntry + "<br/>"; } else { notificationMessage.Message += logEntry + Environment.NewLine; } } } // Create the message in our mail system mailMessage.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(notificationMessage.Message, null, notificationMessage.MediaType)); } // Get the network credentials for the email account we're going to send the notification through networkCredentials = new NetworkCredential( ConfigurationManager.AppSettings.Get("ManyWho.SendGrid.Username"), ConfigurationManager.AppSettings.Get("ManyWho.SendGrid.Password") ); // Create the smtp client using SSL only smtpClient = new SmtpClient( ConfigurationManager.AppSettings.Get("ManyWho.SendGrid.SMTP"), Convert.ToInt32(587) ); smtpClient.EnableSsl = true; smtpClient.Credentials = networkCredentials; // Send ye olde message smtpClient.Send(mailMessage); } catch (Exception) { throw; } finally { // Clear the list of messages with a new list ready for the next notification to be sent this.NotificationMessages = new List <INotificationMessage>(); this.LogEntries = new List <String>(); } }