C#使用QQ邮箱发送邮件

首先要开通QQ邮箱的STMP服务。QQ邮箱——设置——账户——开启SMTP服务。

需要引用:

using System.Net;  
using System.Net.Mail;
using System.Text;

 具体代码如下:

public static void SendEmail(string fromAddr,string psw, string toAddr,string subject, string body)
{
    MailMessage myMail = new MailMessage();

    myMail.From = new MailAddress(fromAddr);
    myMail.To.Add(new MailAddress(toAddr));

    myMail.Subject = subject;
    myMail.SubjectEncoding = Encoding.UTF8;

    myMail.Body = body;
    myMail.BodyEncoding = Encoding.UTF8;
    myMail.IsBodyHtml = true;

    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.qq.com";
    smtp.Credentials = new NetworkCredential(fromAddr, psw);

    smtp.Send(myMail);
}

 

posted @ 2014-08-24 21:35  爹子王  阅读(1371)  评论(0编辑  收藏  举报