码迷,mamicode.com
首页 > Windows程序 > 详细

C#发送邮件

时间:2016-05-27 14:27:34      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

直接附录主要的代码吧

static void Main(string[] args)
{
  SmtpClient client = new SmtpClient("smtp.126.com");
  MailAddress from = new MailAddress("*****@126.com", "***", Encoding.UTF8);//发信箱
  MailAddress to = new MailAddress("*****@qq.com", "****", Encoding.UTF8);//收信地址
  MailMessage message = new MailMessage(from, to);
  Attachment atta = new Attachment(@"C:\Users\HBD\Desktop\蔡英文520就职演说全文.txt");//文件路径
  message.Attachments.Add(atta);
  message.Subject = "测试主题";
  message.SubjectEncoding = Encoding.UTF8;
  message.Body = "邮件内容";
  message.BodyEncoding = Encoding.UTF8;
  client.DeliveryMethod = SmtpDeliveryMethod.Network;
  client.UseDefaultCredentials = false;
  NetworkCredential myNP = new NetworkCredential("*******@126.com", "*****");//账户和密码
  client.Credentials = myNP;
  client.Send(message);
}

C#发送邮件

标签:

原文地址:http://www.cnblogs.com/autumn-he/p/5534383.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!