日期:2014-05-16 浏览次数:20505 次
public static void SendMailUseGmail()
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add("***@***.com");
msg.From = new MailAddress("***@***.com", "test", 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("***@***.com", "****");
client.Port = 465;
client.Host = "smtp.exmail.qq.com";
client.EnableSsl = true;//经过ssl加密
client.DeliveryMethod = SmtpDeliveryMethod.Network;
object userState = msg;
try
{
client.Send(msg);
Console.Write("发送成功");
}
catch (System.Net.Mail.SmtpException ex)
{
Console.Write("发送失败");
}
}
using System;
using System.Collections.Gener