Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1.     public static class SendEmail
  2.     {
  3.         public static void SendMail()
  4.         {
  5.             var fromAddress = new MailAddress("(myemail1)@gmail.com", "name");
  6.             var toAddress = new MailAddress("(myemail2)@hotmail.com", "name2");
  7.             const string fromPassword = "(myemail1Password)";
  8.             const string subject = "Subject_test";
  9.             const string body = "Body_test";
  10.  
  11.             var smtp = new SmtpClient
  12.             {
  13.                 Host = "smtp.gmail.com",
  14.                 Port = 587,
  15.                 EnableSsl = true,
  16.                 DeliveryMethod = SmtpDeliveryMethod.Network,
  17.                 Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
  18.             };
  19.  
  20.             using (var message = new MailMessage(fromAddress, toAddress)
  21.             {
  22.                 Subject = subject,
  23.                 Body = body
  24.             })
  25.             {
  26.                 smtp.Send(message);
  27.             }
  28.         }
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement