引用命名空间Sytem.Net.Mail,代码使用如下:
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("发件邮箱地址", "发件人名字");
mailMessage.To.Add("收件邮箱地址"); // 非企业邮箱,一次只能发一个邮件地址,不能群发
mailMessage.Subject = "邮件标题";
mailMessage.Body = "邮件正文";
SmtpClient client = new SmtpClient("smtp.qq.com");// 发件服务器
client.Credentials = new NetworkCredential("发件账号", "发件授权码");
client.Send(mailMessage);
QQ邮箱举例:
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("888888888@qq.com", "发件人姓名");
mailMessage.To.Add("111111111@qq.com"); // 非企业邮箱,一次只能发一个邮件地址,不能群发
mailMessage.Subject = "邮件标题";
mailMessage.Body = "邮件正文";
SmtpClient client = new SmtpClient("smtp.qq.com");// 发件服务器
client.Credentials = new NetworkCredential("888888888", "erggdrgdrtgttfh334");
client.Send(mailMessage);