private void sendmail()
{
MailMessage message = new MailMessage();
message.SubjectEncoding = Encoding.BigEndianUnicode; //邮件编码
var from = new MailAddress("henl@gmail.com", "Hello");//你的邮
message.From = from;
message.To.Add(new MailAddress("aaa@qq.com"));
message.Subject = "测试邮件";
message.CC.Add(new MailAddress("abc@qq.com")); //抄送
message.IsBodyHtml = true; //正文是否是HTML
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Body = "邮件发送测试"; //正文
//message.Attachments.Add(new Attachment(@"c:\1.txt")); //附件
message.Priority = System.Net.Mail.MailPriority.High; //优先级
SmtpClient client = new SmtpClient("smtp.gmail.com", 587); // 587;//Gmail使用的端口
client.Credentials = new System.Net.NetworkCredential("henl@gmail.com", "123456"); //这里是申请的邮箱和密码
client.EnableSsl = true; //必须经过ssl加密
try
{
client.Send(message);
MessageBox.Show("邮件已经成功发送到" + message.To.ToString());
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}