OpenSmtp 发送邮件
2013-12-04 17:42
399 查看
1.采用发送一个简单邮件
示例:
示例:
private int smtpPort; private string smtpHost; private int recieveTimeout; private int sendTimeout; private string subject; private string body; private StringBuilder htmlBody; private Smtp smtp; private MailMessage msg; private EmailAddress senderAddress; private EmailAddress replyToAddress; private EmailAddress recipientAddress; private EmailAddress ccAddress; private EmailAddress bccAddress; subject = "Test Subject 哈哈 International: ËÇÅÃÄÄÅÂÀèéêëìí"; body = "Hello Jane.\r\n This is the body of the mail message. \r\nInternational chars: ËÇÅÃÄÄÅÂÀèéêë\r\nìíîïñaÿc"; htmlBody = new StringBuilder(); htmlBody.Append("<HTML><HEAD></HEAD><BODY bgColor=\"#00ffff\"><b>Hello Jane. This is the body of the HTML mail message. International chars: ËÇÅÃÄÄÅÂÀèéêëìíîïñaÿc</b></BODY></HTML>"); senderAddress = new EmailAddress("sulin11026@163.com", "John Sender"); recipientAddress = new EmailAddress("sulin@moneybrace.com", "Jane Doe"); ccAddress = new EmailAddress("ccAddress@localhost", "CC Name"); bccAddress = new EmailAddress("bccAddress@localhost", "BCC Name"); msg = new MailMessage(senderAddress, recipientAddress); smtpHost = "smtp.163.com"; smtpPort = 25; smtp = new Smtp(); smtp.Host = smtpHost; smtp.Port = smtpPort; msg.Subject = subject; msg.Body = body; msg.AddImage(Server.MapPath("context/test.jpg"), "testimage"); msg.AddImage(Server.MapPath("omnipay.jpg"), "omnipay"); msg.HtmlBody = "<body><table><tr><td><b>Here is an embedded IMAGE:<img src=\"cid:testimage\"></td></tr>\r\n<tr><td>Here's another: <img src=\"cid:omnipay\"></td></tr></table></body>"; //htmlbody 会覆盖body 的内容 msg.AddRecipient(ccAddress, AddressType.Cc); msg.AddRecipient(bccAddress, AddressType.Bcc); msg.AddAttachment(Server.MapPath("context/test.jpg")); msg.AddAttachment(new Attachment(new FileStream(Server.MapPath("context/test.htm"), FileMode.Open, FileAccess.Read), "test.html")); msg.AddCustomHeader("X-FakeTestHeader", "Fake Value"); msg.AddCustomHeader("X-AnotherFakeTestHeader", "Fake Value"); msg.Notification = true; msg.Charset = "UTF-8"; msg.Priority = MailPriority.Low; smtp.Username = "sulin11026@163.com"; smtp.Password = "**********"; smtp.SendMail(msg);
相关文章推荐
- Linux下使用Shell脚本改变当前工作路径
- 【转发】浅析淘宝网首页信息架构的变迁
- Archlinux论坛
- Windows和Linux换行符的区别
- Hadoop 2.2.0 Symlink的使用
- Linux 配置文件详解 - 引用
- stagefright与opencore对比
- Linux上ln命令详细说明及软链接和硬链接的区别
- Linux上ln命令详细说明及软链接和硬链接的区别
- linux AWK 笔记
- 阿里云centOS-6.3-64位通过YUM源安装nginx
- linux 安装oracl 客户端
- Linux 上的TC 流量控制几个例子(80端口流量限制)
- hadoop_并行写操作思路_2
- WIN7 下 explorer 进行的文件移动COPY HOOK
- Linux kernel启动参数
- Linux 上如何创建新的用户,并让其在首次登陆后修改密码,并限制其允许使用的磁盘空间
- 当装了两个tomcat后,如何修改tomcat端口
- Nginx+mysql+php 在linux上安装
- Linux Administrator's Guid - 系统资源管理命令