Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Net.Mail;
  5.  
  6. namespace TestEmail
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12.  
  13. string username = "office@twinklestar.ro";
  14. string pass = "Ianuarie!123";
  15. string sentTo = "mirela.zavate@easymedical.ro";
  16. List<string> cc = new List<string>();
  17. List<string> attach = new List<string>();
  18. string subject = "test";
  19. string body = "test";
  20. string host = "bssd02.octosquid.com";//mail.twinklestar.ro" ;
  21. string port = "465";
  22. string fromDisplayName = "office@twinklestar.ro";
  23. string fromEmail = "office@twinklestar.ro";
  24. string enableSSL = "1";
  25. SendFullEmails(username, pass, sentTo, cc, attach, subject, body, host, port, fromDisplayName, fromEmail,
  26. enableSSL);
  27.  
  28. }
  29. public static void SendFullEmails(string credentialUserName, string credentialPassword, string sentTo, List<string> sendCC,
  30. List<string> attachments, string subject, string body, string smtpHost, string smtpPort, string fromDisplayName,
  31. string fromEmailAddress, string enableSSL)
  32. {
  33.  
  34. try
  35. {
  36. MailMessage msgMail = new MailMessage(new MailAddress(fromEmailAddress, fromDisplayName), new MailAddress(sentTo));
  37. msgMail.Subject = subject;
  38. msgMail.IsBodyHtml = true;
  39. msgMail.Body = body;
  40.  
  41. foreach (string cc in sendCC)
  42. msgMail.CC.Add(new MailAddress(cc));
  43.  
  44. foreach (string attach in attachments)
  45. msgMail.Attachments.Add(new Attachment(attach));
  46.  
  47. SmtpClient client = new SmtpClient(smtpHost);
  48. client.Port = Convert.ToInt32(smtpPort);
  49. //client.UseDefaultCredentials = false;
  50. // client.DeliveryMethod = SmtpDeliveryMethod.Network;
  51. //client.Timeout = 600000;
  52. client.Credentials = new System.Net.NetworkCredential(credentialUserName, credentialPassword);
  53. //client.UseDefaultCredentials = true;
  54. if (enableSSL == "1")
  55. client.EnableSsl = true;
  56. else
  57. client.EnableSsl = false;
  58. client.Send(msgMail);
  59.  
  60. }
  61. catch (Exception ex)
  62. {
  63. throw ex;
  64. }
  65.  
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement