using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Mail;
namespace EmailTest
{
class ssl
{
/// <summary>
/// 發郵件
/// </summary>
public static void SendMailUseQQmail()
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add("[email protected]");
/*
msg.To.Add("[email protected]");
* msg.To.Add("[email protected]");
* msg.To.Add("[email protected]");可以發送給多人
*/
msg.CC.Add("[email protected]");
/*
* msg.CC.Add("[email protected]");
* msg.CC.Add("[email protected]");可以抄送給多人
*/
msg.From = new MailAddress("a.qq.com", "Me", System.Text.Encoding.UTF8);
/* 上面3個參數分别是發件人位址(可以随便寫),發件人姓名,編碼*/
msg.Subject = "這是測試郵件";//郵件标題
msg.SubjectEncoding = System.Text.Encoding.UTF8;//郵件标題編碼
msg.Body = "郵件内容郵件内容郵件内容郵件内容郵件内容";//郵件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//郵件内容編碼
msg.IsBodyHtml = false;//是否是HTML郵件
msg.Priority = MailPriority.High;//郵件優先級
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("qq.qq.com", "qq密碼或者授權碼");
//見下圖1
//上述寫你的QQ郵箱和密碼
client.Port = 587;//QQ郵箱使用的端口
client.Host = "smtp.qq.com";
client.EnableSsl = true;//經過ssl加密
object userState = msg;
try
{
client.SendAsync(msg, userState);
//簡單一點兒可以client.Send(msg);
Console.Write("SSL.Success");
Console.ReadKey();
}
catch (System.Net.Mail.SmtpException ex)
{
Console.WriteLine("SSL.Fail");
Console.ReadKey();
}
}
}
}

qq郵箱-設定-賬戶