标签:
using System; using System.Collections; using System.Text; using System.Net; using System.Net.Mail; namespace NetMailSend { class Programe { /// <summary> /// C#发送邮件需要使用命名空间System.Net.Mail /// 同时会使用到MailMessage和SmtpClient两个类 /// </summary> /// <param name="args"></param> public static void Main(string[] args) { //mail message //实例化MailMessage,调用有参构造,传入发送者和接受者的邮箱地址,发送者不是是gmail邮箱 MailMessage myMail = new MailMessage("zxx1978@gmail.com","479224006@qq.com"); myMail.Subject = "Test"; //邮件标题 myMail.Body = "You are<br> successed."; //邮件内容 //设置邮件的优先级别(必写) myMail.Priority = MailPriority.High; //smtp client SmtpClient sender = new SmtpClient(); sender.Host = "smtp.gmail.com"; //设置主机名称或IP地址 sender.Port = 587; //设置SMTP端口 //设置发件人的邮箱和密码 sender.Credentials = new NetworkCredential("zxx1978@gmail.com", "zhao1978"); sender.EnableSsl = true; //设置是否套用加密连接(必写) try { sender.Send(myMail); //发送邮件 Console.WriteLine("Success"); } catch (Exception e) { Console.WriteLine("Failed.Exception:{0}", e.Message); } Console.Write("Press any key to quit..."); Console.ReadKey(); } } }
上面创建的是控制台应用程序!
标签:
原文地址:http://www.cnblogs.com/duanjt/p/5174627.html