Guest User

Untitled

a guest
Sep 6th, 2018
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. C# how to send email?
  2. new SmtpClient("smtp.server.com", 25).Send("test@hotmail.com",
  3. "test@gmail.com",
  4. "subject",
  5. "body");
  6.  
  7. MailMessage mailMsg = new MailMessage();
  8. mailMsg.To.Add("test@hotmail.com");
  9. // From
  10. MailAddress mailAddress = new MailAddress("you@hotmail.com");
  11. mailMsg.From = mailAddress;
  12.  
  13. // Subject and Body
  14. mailMsg.Subject = "subject";
  15. mailMsg.Body = "body";
  16.  
  17. // Init SmtpClient and send on port 587 in my case. (Usual=port25)
  18. SmtpClient smtpClient = new SmtpClient("mailserver", Convert.ToInt32("587"));
  19. System.Net.NetworkCredential credentials =
  20. new System.Net.NetworkCredential("username", "password");
  21. smtpClient.Credentials = credentials;
  22.  
  23.  
  24. smtpClient.Send(mailMsg);
Add Comment
Please, Sign In to add comment