message.From = new MailAddress("flyayay@gmail.com", "Hello");//你的邮
message.To.Add(new MailAddress("flyayay@qq.com"));
message.Subject = "测试邮件" ;
message.CC.Add(new MailAddress(flyayay@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("flyayay@gmail.com", "***********"); //这里是申请的邮箱和密码
client.EnableSsl = true; //必须经过ssl加密
try
{
client.Send(message);
MessageBox.Show("邮件已经成功发送到" + message.To.ToString());
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}