发送邮件
/// <summary>
///
/// </summary>
/// <param name="to">收件箱</param>
/// <param name="from">发件箱</param>
/// <param name="name">发件人</param>
/// <param name="subject">标题</param>
/// <param name="content">内容</param>
/// <param name="mail">邮箱账号</param>
/// <param name="passWord">邮箱密码</param>
/// <returns></returns>
public bool SendMailUseGmail(string to,string from ,string name,string subject,string content,string mail,string passWord)
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add(to);
msg.From = new MailAddress(from, name, System.Text.Encoding.UTF8);
msg.Subject = subject;//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = content;//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = true;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(mail, passWord);
//上述写你的GMail邮箱和密码
client.Port = 587;//Gmail使用的端口
client.Host = "smtp.gmail.com";
client.EnableSsl = true;//经过ssl加密
object userState = msg;
try
{
//client.SendAsync(msg, userState);
client.Send(msg);
}
catch
{
return false;
}
return true;
}