3023e9e23e9dad97ea615cb94f21dbd223dc8f09.svn-base 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.Mail;
  6. using System.Web;
  7. namespace iBemsDataService.Controllers.Fms.WorkManagement.ScheduledTask
  8. {
  9. public class AlarmConfigEmail
  10. {
  11. //private MailAddress sendAddress = new MailAddress("icontrolslaboratory@gmail.com");
  12. private MailAddress toAddress = null;
  13. private MailAddress sendAddress = null;
  14. //private string sendPassword = "icontrols123.,";
  15. private string sendPassword = null;
  16. public void SetToAddress(string toMail)
  17. {
  18. this.toAddress = new MailAddress(toMail);
  19. }
  20. // Email 정보 가져오기 2019.04.
  21. public void SetEmailInfo(string fromAdress, string fromPassword)
  22. {
  23. this.sendAddress = new MailAddress(fromAdress);
  24. this.sendPassword = fromPassword;
  25. }
  26. // Email 정보 가져오기 2019.04.
  27. public string SendEmail(String subject, string body)
  28. {
  29. SmtpClient smtp = null;
  30. MailMessage message = null;
  31. try
  32. {
  33. smtp = new SmtpClient
  34. {
  35. Host = "smtp.gmail.com",
  36. EnableSsl = true,
  37. DeliveryMethod = SmtpDeliveryMethod.Network,
  38. Credentials = new NetworkCredential(sendAddress.Address, sendPassword),
  39. Timeout = 20000
  40. };
  41. message = new MailMessage(sendAddress, toAddress)
  42. {
  43. Subject = subject,
  44. Body = body
  45. };
  46. smtp.Send(message);
  47. return "OK";
  48. }
  49. catch
  50. {
  51. return "FAIL";
  52. }
  53. finally
  54. {
  55. if (smtp != null) { smtp.Dispose(); }
  56. if (message != null) { message.Dispose(); }
  57. }
  58. }
  59. }
  60. }