Example #1
0
 public ReturnValue SendEmail(string toAddress, string toName, string subject, string messageBody,
                              string fromName = "", string fromAddress = "")
 {
     var retVal = new ReturnValue() {Message = "Email Sent Successfully"};
     if (EmailsEnabled)
     {
         var message = GenerateMailMessage(toAddress, toName, subject, messageBody, fromName, fromAddress);
         SendMessage(retVal, message);
     }
     else retVal.SetFailMessage("Email sending functionality is currently disabled");
     return retVal;
 }
Example #2
0
 private void SendMessage(ReturnValue retVal, MailMessage message)
 {
     try
     {
         var client = new SmtpClient(SmtpHost);
         if ((!string.IsNullOrWhiteSpace(SmtpUsername)) && (!string.IsNullOrWhiteSpace(SmtpPassword)))
         {
             client.UseDefaultCredentials = false;
             client.Credentials = new NetworkCredential(SmtpUsername, SmtpPassword);
         }
         client.Send(message);
     }
     catch (Exception ex)
     {
         retVal.SetFailMessage("Failed to send email: " + ex.Message);
     }
 }