Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. public bool SendAnnouncementCreationNotification(string toEmail, string announcementTitle, string announcementDescription)
  2. {
  3. string from = ConfigurationManager.AppSettings["ContactEmailAddress"].ToString();
  4.  
  5. string subject = "AAID - New Announcement";
  6.  
  7. string smtpClient = ConfigurationManager.AppSettings["SmtpClient"].ToString();
  8. string smtpUser = ConfigurationManager.AppSettings["SmtpUser"].ToString();
  9. string smtpPassword = ConfigurationManager.AppSettings["SmtpPassword"].ToString();
  10. int port = 0;
  11. int.TryParse(ConfigurationManager.AppSettings["SmtpPort"], out port);
  12.  
  13. StringBuilder mailBody = new StringBuilder();
  14. mailBody.AppendFormat("<p>Hello!</p>");
  15. mailBody.AppendFormat("<br />");
  16. mailBody.AppendFormat(string.Format("<p>A new announcement - {0} - has been created", announcementTitle));
  17. mailBody.AppendFormat("<p>" + announcementDescription + "</p>");
  18. mailBody.AppendFormat("<br />");
  19. mailBody.AppendFormat("<p>With all best wishes,</p>");
  20. mailBody.AppendFormat("<p>The AAID team</p>");
  21. string body = mailBody.ToString();
  22.  
  23. MailMessage email = new MailMessage(from, toEmail, subject, body);
  24. email.IsBodyHtml = true;
  25.  
  26. SmtpClient client = new SmtpClient(smtpClient, port);
  27.  
  28. client.UseDefaultCredentials = false;
  29. client.Credentials = new NetworkCredential(smtpUser, smtpPassword);
  30. client.EnableSsl = enabledSSL;
  31.  
  32. try
  33. {
  34. client.Send(email);
  35. return true;
  36. }
  37. catch (Exception ex)
  38. {
  39. return false;
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement