C# 发送邮件代码

时间:2022-01-11 18:08:41

C# 发送邮件代码

   MailMessage mailMsg = new MailMessage(); //using System.Net; 引用
mailMsg.From = new MailAddress("lcfhn168@163.com", "lichunfang");//发件邮箱
mailMsg.To.Add(new MailAddress("459928575@qq.com", "lichunfang"));//收件邮箱
mailMsg.Subject = "Hello ..."; //主题
mailMsg.Body = "ni hao ,,,,,";//.内容
SmtpClient client = new SmtpClient("smtp.163.com"); //smtp.126.com smtp.qq.com
client.Credentials = new NetworkCredential("lcfhn168", "");//用户名,密码
client.Send(mailMsg);