zoukankan      html  css  js  c++  java
  • 发送邮件

    private static string emailAccount = WebConfigurationManager.AppSettings["emailAccount"];
            private static string emailPwd = WebConfigurationManager.AppSettings["emailPwd"];
            private static string emailCode = WebConfigurationManager.AppSettings["emailCode"];
            private static string emailPOP3 = WebConfigurationManager.AppSettings["emailPOP3"];
            private static string emailSMTP = WebConfigurationManager.AppSettings["emailSMTP"];
            private static string emailIMAP = WebConfigurationManager.AppSettings["emailIMAP"];


    1 普通发送邮件

    public static void SendMailByEmail(string[] file,string subject = "", string body = "", List<string> receivers = null)
            {
                MailMessage message = new MailMessage();
                MailAddress fromAddr = new MailAddress(emailAccount);
                message.From = fromAddr;
                foreach (var item in receivers)
                {
                    message.To.Add(item);
                }
                foreach (var item in file)
                {
                    if (string.IsNullOrEmpty(item))
                        continue;
                    message.Attachments.Add(new Attachment(item));
                }
                message.Subject = subject;
                message.SubjectEncoding = Encoding.UTF8;
                message.Body = body;
                //允许html标签
                message.IsBodyHtml = true;
                message.BodyEncoding = Encoding.UTF8;  
                SmtpClient client = new SmtpClient(emailSMTP, 25);
                client.UseDefaultCredentials = true;
                client.Credentials = new NetworkCredential(emailAccount, emailCode);
                client.EnableSsl = true;
    
                //避免远程证书无效
                ServicePointManager.ServerCertificateValidationCallback =
    delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; };
    
                client.Send(message);
            }


    2 使用默认邮件发送

    public static void SendEmail_Process(string subject = "", string body = "", string receivers = "")
            {
                //Process.Start(new ProcessStartInfo("mailto:user@126.com?subject=test&body=Dear:%0A%0DThis is a test mail."));
                string email = string.Format("mailto:{0}?subject={1}&body={2}"
                    , receivers
                    , subject
                    , body);
                Process.Start(new ProcessStartInfo(email));
            }
  • 相关阅读:
    oracle之三 自动任务调度
    oracle之三资源管理
    oracle之三rman 维护
    oracle之三目录库和辅助库
    oracle之三rman 不完全恢复
    oracle之三rman 备份
    oracle之三rman 完全恢复
    oracle之三RMAN概述
    oracle之三闪回flashback
    Vimium
  • 原文地址:https://www.cnblogs.com/hanjun0612/p/9779855.html
Copyright © 2011-2022 走看看