需要2个引用
using System.Net;
using System.Net.Mail;
using (MailMessage mailMessige=new MailMessage()) using (SmtpClient smtpClient=new SmtpClient(/*smtp服务器*/"smtp.163.com")) { mailMessige.To.Add(/*收件人地址*/""); mailMessige.Body=/*内容*/"Ni hao"; mailMessige.From = new MailAddress(/*发送的地址*/""); mailMessige.Subject = "邮件标题"; smtpClient.Credentials = new NetworkCredential("邮箱账号", "邮箱授权码"); smtpClient.Send(mailMessige); }
有几点是要注意的
SMTP服务器的地址 和授权密码 要在邮箱的设置里面 找到