• OpenSmtp 发送邮件


    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);
  • 相关阅读:
    010.Python文件指针与文件修改
    009.Python之with管理与文件操作的其他方法
    008.Python之文件的基本操作
    007.Python基础数据类型之元组、字典与集合
    006.Python基础数据类型之字符串与列表
    005.python基础之循环结构与数字类型数据
    004.python基础知识3
    003.python基础知识2
    002.python基础知识1
    001.计算机基础知识
  • 原文地址:https://www.cnblogs.com/linsu/p/3458069.html
Copyright © 2020-2023  润新知