/// <summary> /// Sends a test email to the primary administrator to ensure that it works. /// </summary> /// <param name="smtpServer">The SMTP server to send a test email to.</param> /// <returns>A boolean value indicating whether the test succeeded.</returns> public bool RunTest(string smtpServer) { try { string systemEmail = Config.Application.Settings.GetString("SystemEmail"); if (systemEmail == null || systemEmail == String.Empty) { return(false); } MailMessage message = new MailMessage(systemEmail, systemEmail, "Test Email", "Test Worked!"); Emailer.CreateSmtpClient().Send(message); return(true); } catch (SmtpException) { return(false); } }
/// <summary> /// Sends the provided notification message to the provided notifiable users. /// </summary> /// <param name="entity">The recipients of the notification.</param> /// <param name="entity">The entity involved in the event that users are being notified about.</param> /// <param name="subject">The subject of the email to send to the provided notifiable users.</param> /// <param name="message">The message of the email to send to the provided notifiable users.</param> public virtual void SendNotification(User[] recipients, IEntity entity, string subject, string message) { using (LogGroup logGroup = LogGroup.StartDebug("Sending a notification to the provided recipients.")) { LogWriter.Debug("Recipients: " + recipients.Length.ToString()); foreach (User user in recipients) { if (user != null && user.EnableNotifications) { LogWriter.Debug("To: " + user.Email); string replyTo = "*****@*****.**"; if (Config.Application.Settings.ContainsKey("SystemEmail")) { replyTo = Config.Application.Settings.GetString("SystemEmail"); } else { LogWriter.Error("No system email has been set. Notification emails have '*****@*****.**' in the reply field instead."); } LogWriter.Debug("Reply to: " + replyTo); try { MailMessage mm = new MailMessage(replyTo, user.Email, PrepareNotificationText(subject, entity), PrepareNotificationText(message, entity)); Emailer.CreateSmtpClient().Send(mm); } catch (FormatException ex) { LogWriter.Error(ex); } catch (SmtpFailedRecipientException ex) { LogWriter.Error(ex); } catch (SmtpException ex) { LogWriter.Error(ex); } } } } }
public void ExecuteSend(MailMessage message) { Emailer.CreateSmtpClient().Send(message); }