Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3.  
  4. // Source of data. Fetch the emails from Database and put it to the list.
  5. List<string> listOfEmails = new List<string>() { "MariusJusc@gmail.com", "dorota.kortisova14@gmail.com" };
  6.  
  7. foreach (var mail in listOfEmails)
  8. {
  9. try
  10. {
  11. MailMessage mailM = new MailMessage();
  12. SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
  13.  
  14. // Email from which is being sent.
  15. mailM.From = new MailAddress("EMAIL_FROM");
  16.  
  17. //Email to which is being sent.
  18. // We take every email that is in the list (listOfEmails) and we put it to send.
  19. mailM.To.Add(mail);
  20.  
  21. //Email subject.
  22. mailM.Subject = "SUBJECT_EMAIL";
  23.  
  24. // Email message.
  25. mailM.Body = "Sending email without any server....... Love you babe <3";
  26.  
  27. SmtpServer.Port = 587;
  28. // Credentials from the account you are sending.
  29. SmtpServer.Credentials = new System.Net.NetworkCredential("EMAIL", "PASSWORD");
  30. SmtpServer.EnableSsl = true;
  31.  
  32. SmtpServer.Send(mailM);
  33.  
  34. //Check if the email was sent succesfuly.
  35. Console.WriteLine("Email sent.");
  36. Console.ReadLine();
  37. }
  38. catch (Exception ex)
  39. {
  40. Console.WriteLine(ex.ToString());
  41. Console.ReadLine();
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement