• 利用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("XXX@XXX.com");
                //mail.To.Add("GuoliXia@wistronits.com");
                mail.To.Add("XXX@XXX.com");
                mail.CC.Add("XXXX@XXX.com");
                mail.Bcc.Add("XXXX@XXX.com");
                mail.Body = "<p>hello</p><table><tr><td>1234</td></tr></table>";
                mail.Attachments.Add(new Attachment(@"C:ReportXXXXX_20140214.xls"));
                mail.Attachments.Add(new Attachment(@"C:ReportXXXXX_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替代了

  • 相关阅读:
    使用kendynet构建异步redis访问服务
    使用kendynet编写网关服务
    作为前端,我为什么选择 Angular 2?
    你必须知道的Javascript 系列
    JS日期(Date)处理函数总结
    JS数组(Array)处理函数总结
    消息推送之APNS
    消息推送之GCM
    Linux常用命令大全
    Sequential Container
  • 原文地址:https://www.cnblogs.com/xiaoshuai1992/p/sendmail.html
Copyright © 2020-2023  润新知