C#使用Smtp,通过qqmail发送邮件

public static void SendEMail(string senderEmail, string senderAuthCode, string smtpHost, int smtpPort,
string receiverEmail, string subject, string body)
{
MailMessage msg = new MailMessage();
msg.To.Add(receiverEmail);
//msg.To.Add([email protected]);
//msg.CC.Add("[email protected]");可以抄送给多人

msg.From = new MailAddress(senderEmail);
msg.Subject = subject;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = body;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = false;
msg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential(senderEmail, senderAuthCode);//senderAuthCode不是qq邮箱登录密码,需要在qq邮箱,设置>账户>smtp...,生成授权码
client.Port = smtpPort;//QqMail:587(注意:465是无效的)
client.Host = smtpHost;// "smtp.qq.com";
client.EnableSsl = true;//经过ssl加密
client.Send(msg);
}

转载于:https://www.cnblogs.com/erentec/p/11066226.html

你可能感兴趣的:(C#使用Smtp,通过qqmail发送邮件)