日期:2014-05-17 浏览次数:20405 次
string fromAddress = "***@gmail.com"; System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); msg.To.Add(targetAddress); msg.From = new System.Net.Mail.MailAddress(fromAddress,"***"); msg.BodyEncoding = System.Text.Encoding.UTF8; /* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/ msg.Subject = title;//邮件标题 msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码 msg.Body = content;//邮件内容 msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码 msg.IsBodyHtml = true;//是否是HTML邮件 msg.Priority = System.Net.Mail.MailPriority.High;//邮件优先级 System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); client.Credentials = new System.Net.NetworkCredential(fromAddress, "***"); //上述写你的GMail邮箱和密码 client.Port = 587;//Gmail使用的端口 client.Host = "smtp.gmail.com"; client.EnableSsl = true;//经过ssl加密 object userState = msg; client.SendAsync(msg, userState);