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("1185172056@qq.com");
/*
msg.To.Add("b@b.com");
* msg.To.Add("b@b.com");
* msg.To.Add("b@b.com");可以发送给多人
*/
msg.CC.Add("2670828470@qq.com");
/*
* msg.CC.Add("c@c.com");
* msg.CC.Add("c@c.com");可以抄送给多人
*/
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();
}
}
}
}