The email account and password used below are not authentic. If you need to test the password, replace it with your own email account.
To be referenced:
Using System. Net. Mail;
Using System. Text;
Using System. Net;
Program code:
MailMessage myMail = new MailMessage (); // create an email Instance Object
MyMail. From = new MailAddress ("bluesky@sina.com"); // sender, which corresponds to the verification information of the mail server and cannot be changed at will
MyMail. To. Add (new MailAddress ("848594@qq.com"); // recipient
MyMail. Subject = "C # Send Email"; // mail title
MyMail. SubjectEncoding = Encoding. UTF8; // Title Encoding
MyMail. Body = "this is a test email! "; // Email content
MyMail. BodyEncoding = Encoding. UTF8; // email Content Encoding
MyMail. IsBodyHtml = true; // whether the email content supports html
SmtpClient smtp = new SmtpClient (); // create an smtp Instance Object
Smtp. Host = "mail.sina.com"; // Mail Server SMTP
Smtp. Port = 25; // mail server Port
Smtp. Credentials = new NetworkCredential ("bluesky@sina.com", "123456"); // Mail Server verification information
Smtp. Send (myMail); // Send an email
Example of sending emails using Gmail
MailMessage myMail = new MailMessage ();
MyMail. From = new MailAddress ("bluesky@gmail.com ");
MyMail. To. Add (new MailAddress ("444354@qq.com "));
MyMail. Subject = "C # Send Email ";
MyMail. SubjectEncoding = Encoding. UTF8;
MyMail. Body = "this is a test email from gmail! <A href = 'HTTP: // www.sina.com.cn '> sina </a> ";
MyMail. BodyEncoding = Encoding. UTF8;
MyMail. IsBodyHtml = true;
SmtpClient smtp = new SmtpClient ();
Smtp. Host = "smtp.gmail.com ";
Smtp. Port = 587; // smtp Port of Gmail
Smtp. Credentials = new NetworkCredential ("bluesky@gmail.com", "123456 ");
Smtp. EnableSsl = true; // Gmail requires SSL connection
Smtp. DeliveryMethod = SmtpDeliveryMethod. Network; // The sending method of Gmail is through the Network. You must specify
Smtp. Send (myMail );
Example of sending an email using QQ mail
MailMessage myMail = new MailMessage ();
MyMail. From = new MailAddress ("4443233@qq.com ");
MyMail. To. Add (new MailAddress ("bluesky@gmail.com "));
MyMail. Subject = "C # Send Email ";
MyMail. SubjectEncoding = Encoding. UTF8;
MyMail. Body = "this is a test email from QQ! ";
MyMail. BodyEncoding = Encoding. UTF8;
MyMail. IsBodyHtml = true;
SmtpClient smtp = new SmtpClient ();
Smtp. Host = "smtp.qq.com ";
Smtp. Credentials = new NetworkCredential ("4443233@qq.com", "123456 ");
Smtp. Send (myMail );
Reference from: http://hi.baidu.com/%CA%D8%CD%FB%C0%B6%CC%EC/blog/item/6e5e4d60c9d6776c0d33fa3d.html