利用System.Net.Mail 发送邮件
我这里只是试了一下发mail的功能,感觉.net自带的发mail是比较全的,还是直接上我的code
参数文章:System.Net.Mail 发送邮件 SMTP协议
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Mail; namespace MailSend { public class MainSend { public static void SendMail() { MailMessage mail = new MailMessage(); //屏蔽垃圾箱的功能 mail.Headers.Add("X-Priority", "3"); mail.Headers.Add("X-MSMail-Priority", "Normal"); mail.Headers.Add("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869"); mail.Headers.Add("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2869"); mail.Subject = "測試郵箱功能"; mail.From = new MailAddress("[email protected]"); //mail.To.Add("[email protected]"); mail.To.Add("[email protected]"); mail.CC.Add("[email protected]"); mail.Bcc.Add("[email protected]"); mail.Body = "<p>hello</p><table><tr><td>1234</td></tr></table>"; mail.Attachments.Add(new Attachment(@"C:\Report\XXXXX_20140214.xls")); mail.Attachments.Add(new Attachment(@"C:\Report\XXXXX_20140213.xls")); mail.BodyEncoding = System.Text.Encoding.UTF8; mail.IsBodyHtml = true; mail.Priority = MailPriority.High; SmtpClient client = new SmtpClient(); client.Host = "XXXXXX"; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential("XXXXX", "!XXXXX"); client.Send(mail); } } }
2.调用
MailSend.MainSend.SendMail();
还是比较简单的,一些地址被我用xxx替代了
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。