1.采用发送一个简单邮件
示例:
1 private int smtpPort; 2 private string smtpHost; 3 private int recieveTimeout; 4 private int sendTimeout; 5 6 private string subject; 7 private string body; 8 private StringBuilder htmlBody; 9 10 private Smtp smtp; 11 private MailMessage msg; 12 private EmailAddress senderAddress; 13 private EmailAddress replyToAddress; 14 private EmailAddress recipientAddress; 15 private EmailAddress ccAddress; 16 private EmailAddress bccAddress; 17 subject = "Test Subject 哈哈 International: ËÇÅÃÄÄÅÂÀèéêëìí"; 18 body = "Hello Jane. This is the body of the mail message. International chars: ËÇÅÃÄÄÅÂÀèéêë ìíîïñaÿc"; 19 htmlBody = new StringBuilder(); 20 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>"); 21 senderAddress = new EmailAddress("sulin11026@163.com", "John Sender"); 22 recipientAddress = new EmailAddress("sulin@moneybrace.com", "Jane Doe"); 23 ccAddress = new EmailAddress("ccAddress@localhost", "CC Name"); 24 bccAddress = new EmailAddress("bccAddress@localhost", "BCC Name"); 25 26 msg = new MailMessage(senderAddress, recipientAddress); 27 smtpHost = "smtp.163.com"; 28 smtpPort = 25; 29 smtp = new Smtp(); 30 smtp.Host = smtpHost; 31 smtp.Port = smtpPort; 32 msg.Subject = subject; 33 msg.Body = body; 34 msg.AddImage(Server.MapPath("context/test.jpg"), "testimage"); 35 msg.AddImage(Server.MapPath("omnipay.jpg"), "omnipay"); 36 msg.HtmlBody = "<body><table><tr><td><b>Here is an embedded IMAGE:<img src="cid:testimage"></td></tr> <tr><td>Here's another: <img src="cid:omnipay"></td></tr></table></body>"; 37 //htmlbody 会覆盖body 的内容 38 msg.AddRecipient(ccAddress, AddressType.Cc); 39 msg.AddRecipient(bccAddress, AddressType.Bcc); 40 41 msg.AddAttachment(Server.MapPath("context/test.jpg")); 42 msg.AddAttachment(new Attachment(new FileStream(Server.MapPath("context/test.htm"), FileMode.Open, FileAccess.Read), "test.html")); 43 44 msg.AddCustomHeader("X-FakeTestHeader", "Fake Value"); 45 msg.AddCustomHeader("X-AnotherFakeTestHeader", "Fake Value"); 46 msg.Notification = true; 47 msg.Charset = "UTF-8"; 48 msg.Priority = MailPriority.Low; 49 50 smtp.Username = "sulin11026@163.com"; 51 smtp.Password = "**********"; 52 53 smtp.SendMail(msg);