首页 > 代码库 > C# 发送qq邮箱

C# 发送qq邮箱

QQ邮箱的简单邮件传输协议(SMTP)使用了SSL加密,必须启用SSL加密、指定端口。

 

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

        protected void Send_Click(object sender, EventArgs e)
        {
            MailMessage msg = new MailMessage();

            msg.To.Add("收件人地址@qq.com");
            msg.CC.Add("抄送人地址@qq.com");

            msg.From = new MailAddress("发件人邮箱@qq.com", "名称");

            msg.Subject = "邮件标题";
            //标题格式为UTF8  
            msg.SubjectEncoding = Encoding.UTF8;

            msg.Body = "邮件内容";
            //内容格式为UTF8 
            msg.BodyEncoding = Encoding.UTF8;

            SmtpClient client = new SmtpClient();
            //SMTP服务器地址 
            client.Host = "smtp.qq.com";
            //SMTP端口,QQ邮箱填写587  
            client.Port = 587;
            //启用SSL加密  
            client.EnableSsl = true;

            client.Credentials = new NetworkCredential("发件人邮箱账号@qq.com", "密码");
            //发送邮件  
            client.Send(msg);
        }

 

C# 发送qq邮箱