Advertisement
andriiAndrii

Untitled

May 3rd, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1.  
  2. public class MailSender
  3. {
  4. public static bool SendEmail(
  5. string pMailRuEmail,
  6. string pMailRuPassword,
  7. string pTo,
  8. string pSubject,
  9. string pBody,
  10. System.Web.Mail.MailFormat pFormat,
  11. string pAttachmentPath="")
  12. {
  13. try
  14. {
  15. System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage();
  16. myMail.Fields.Add
  17. ("http://schemas.microsoft.com/cdo/configuration/smtpserver",
  18. "smtp.mail.ru");
  19. myMail.Fields.Add
  20. ("http://schemas.microsoft.com/cdo/configuration/smtpserverport",
  21. "465");
  22. myMail.Fields.Add
  23. ("http://schemas.microsoft.com/cdo/configuration/sendusing",
  24. "2");
  25. //sendusing: cdoSendUsingPort, value 2, for sending the message using
  26. //the network.
  27.  
  28. //smtpauthenticate: Specifies the mechanism used when authenticating
  29. //to an SMTP
  30. //service over the network. Possible values are:
  31. //- cdoAnonymous, value 0. Do not authenticate.
  32. //- cdoBasic, value 1. Use basic clear-text authentication.
  33. //When using this option you have to provide the user name and password
  34. //through the sendusername and sendpassword fields.
  35. //- cdoNTLM, value 2. The current process security context is used to
  36. // authenticate with the service.
  37. myMail.Fields.Add
  38. ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
  39. //Use 0 for anonymous
  40. myMail.Fields.Add
  41. ("http://schemas.microsoft.com/cdo/configuration/sendusername",
  42. pMailRuEmail);
  43. myMail.Fields.Add
  44. ("http://schemas.microsoft.com/cdo/configuration/sendpassword",
  45. pMailRuPassword);
  46. myMail.Fields.Add
  47. ("http://schemas.microsoft.com/cdo/configuration/smtpusessl",
  48. "true");
  49. myMail.From = pMailRuEmail;
  50. myMail.To = pTo;
  51. myMail.Subject = pSubject;
  52. myMail.BodyFormat = pFormat;
  53. myMail.Body = pBody;
  54. myMail.BodyEncoding = System.Text.Encoding.UTF8;
  55.  
  56. if (pAttachmentPath.Trim() != "")
  57. {
  58. MailAttachment MyAttachment =
  59. new MailAttachment(pAttachmentPath);
  60. myMail.Attachments.Add(MyAttachment);
  61. myMail.Priority = System.Web.Mail.MailPriority.High;
  62. }
  63.  
  64. System.Web.Mail.SmtpMail.SmtpServer = "smtp.mail.ru";
  65. System.Web.Mail.SmtpMail.Send(myMail);
  66. return true;
  67. }
  68. catch (Exception ex)
  69. {
  70. throw;
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement