使用MailMessage和SmtpClient发送邮件
2013-04-23 17:16
633 查看
Console.WriteLine("开始发送邮件....");
//1.MailMessage
//1.创建一封邮件
MailMessage msg = new MailMessage();
msg.From = new MailAddress("szyuxueliang@163.com");
msg.To.Add(new MailAddress("1027206433@qq.com"));
msg.Subject = "======去给我带份饭。=======";
msg.SubjectEncoding = Encoding.GetEncoding("gb2312");
msg.Body = "==================在中午12:00之前把饭送过来。================";
//创建一个html格式的文档
AlternateView aview = AlternateView.CreateAlternateViewFromString("在中午<h1><font color=\"red\">12:00</font></h1>之前把饭送过来。<br/><img src=\"cid:img001\"/>", Encoding.UTF8, "text/html");
//为邮件中增加一张图片
LinkedResource resource = new LinkedResource(@"E:\ASP.NET WorkPlace\MyArticle\MyArticle.WebSite\Content\images\loading.gif");
resource.ContentId = "img001";
aview.LinkedResources.Add(resource);
msg.AlternateViews.Add(aview);
//为邮件增加一些附件
Attachment attchFile1 = new Attachment(@"E:\ASP.NET WorkPlace\MyArticle\MyArticle.WebSite\Content\images\addarticle.gif");
// Attachment attchFile2 = new Attachment(@"E:\HTML.5与CSS.3权威指南.pdf");
//Attachment attchFile3 = new Attachment(@"E:\传智播客视频\【ASP.NET≠拖控件!】-传智播客ASP.NET高手之路视频教程01_单线程缺点和简单多线程操作(1).zip");
msg.Attachments.Add(attchFile1);
// msg.Attachments.Add(attchFile2);
//msg.Attachments.Add(attchFile3);
//2.SmtpClient
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.163.com";
smtp.Credentials = new NetworkCredential("szyuxueliang", "哈哈不告诉你!");
smtp.Send(msg);
Console.WriteLine("发送完毕!");
Console.ReadKey();
//1.MailMessage
//1.创建一封邮件
MailMessage msg = new MailMessage();
msg.From = new MailAddress("szyuxueliang@163.com");
msg.To.Add(new MailAddress("1027206433@qq.com"));
msg.Subject = "======去给我带份饭。=======";
msg.SubjectEncoding = Encoding.GetEncoding("gb2312");
msg.Body = "==================在中午12:00之前把饭送过来。================";
//创建一个html格式的文档
AlternateView aview = AlternateView.CreateAlternateViewFromString("在中午<h1><font color=\"red\">12:00</font></h1>之前把饭送过来。<br/><img src=\"cid:img001\"/>", Encoding.UTF8, "text/html");
//为邮件中增加一张图片
LinkedResource resource = new LinkedResource(@"E:\ASP.NET WorkPlace\MyArticle\MyArticle.WebSite\Content\images\loading.gif");
resource.ContentId = "img001";
aview.LinkedResources.Add(resource);
msg.AlternateViews.Add(aview);
//为邮件增加一些附件
Attachment attchFile1 = new Attachment(@"E:\ASP.NET WorkPlace\MyArticle\MyArticle.WebSite\Content\images\addarticle.gif");
// Attachment attchFile2 = new Attachment(@"E:\HTML.5与CSS.3权威指南.pdf");
//Attachment attchFile3 = new Attachment(@"E:\传智播客视频\【ASP.NET≠拖控件!】-传智播客ASP.NET高手之路视频教程01_单线程缺点和简单多线程操作(1).zip");
msg.Attachments.Add(attchFile1);
// msg.Attachments.Add(attchFile2);
//msg.Attachments.Add(attchFile3);
//2.SmtpClient
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.163.com";
smtp.Credentials = new NetworkCredential("szyuxueliang", "哈哈不告诉你!");
smtp.Send(msg);
Console.WriteLine("发送完毕!");
Console.ReadKey();
相关文章推荐
- 使用MailMessage和SmtpClient类实现asp.net的邮件发送(有详细注释并已测试通过)
- Imail 邮件服务器的SMTP配置与 .NET 下使用 System.Net.SmtpClient 发送邮件
- 使用smtpClient发送邮件时
- 使用.net smtpClient类发送邮件
- 使用SmtpClient发送邮件
- 使用System.Net.Mail.SmtpClient发送邮件时出现的乱码问题
- 关于使用SmtpClient发送邮件
- 使用SmtpClient发送邮件
- .Net使用SmtpClient发送邮件,报错:不允许使用邮箱名称。 服务器响应为: xxxw
- C# 使用 SmtpClient 发送邮件注意项
- windows 8上使用SmtpClient.Send()发送邮件失败的原因分析。
- 使用SmtpClient发送邮件的方法
- 使用 .NET 2.0 的 SmtpClient 类发送邮件
- C# 使用 SmtpClient.SendAsync 方法发送邮件失败,总是返回 Cancelled
- 使用System.Net.Mail.SmtpClient 发送邮件
- 外网IP监测上报程序(使用Poco库的SMTPClientSession发送邮件)
- 在ASP.NET中使用SmtpClient发送邮件
- 利用System.Net.Mail 的SmtpClient发送邮件
- C#使用smtp发送邮件
- python smtplib 使用代理发送邮件