gmail

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net.Mail;
  6. using System.Net;
  7. namespace smtp_client
  8. {
  9. class Program
  10. {
  11. static void Main (string[] args)
  12. {
  13. MailAddress myemail = new MailAddress("me@gmail.com", "Name");
  14. MailAddress mail_to = new MailAddress("receiver@yahoo.com", "Receiver");
  15. string password = "email_password";
  16. SmtpClient Client_smtp = new SmtpClient("smtp.gmail.com", 587);
  17. client_smtp.EnableSsl = true;
  18. client_smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
  19. client_smtp.UseDefaultCredentials = false;
  20. client_smtp.Credentials = new NetworkCredential (myemail.Address, password);
  21. MailMessage message = new MailMessage (myemail, mail_to);
  22. message.Subject = "Hello from sharpcode";
  23. message.Body = "just a test";
  24. client_smtp.Send(message);
  25. }
  26. }
  27. }
原文地址:https://www.cnblogs.com/zeroone/p/3378773.html