Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- // Source of data. Fetch the emails from Database and put it to the list.
- List<string> listOfEmails = new List<string>() { "MariusJusc@gmail.com", "dorota.kortisova14@gmail.com" };
- foreach (var mail in listOfEmails)
- {
- try
- {
- MailMessage mailM = new MailMessage();
- SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
- // Email from which is being sent.
- mailM.From = new MailAddress("EMAIL_FROM");
- //Email to which is being sent.
- // We take every email that is in the list (listOfEmails) and we put it to send.
- mailM.To.Add(mail);
- //Email subject.
- mailM.Subject = "SUBJECT_EMAIL";
- // Email message.
- mailM.Body = "Sending email without any server....... Love you babe <3";
- SmtpServer.Port = 587;
- // Credentials from the account you are sending.
- SmtpServer.Credentials = new System.Net.NetworkCredential("EMAIL", "PASSWORD");
- SmtpServer.EnableSsl = true;
- SmtpServer.Send(mailM);
- //Check if the email was sent succesfuly.
- Console.WriteLine("Email sent.");
- Console.ReadLine();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.ToString());
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement