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

     /// <summary>
            /// 邮件群发
            /// </summary>
            /// <param name="strMyEmail">发送人邮件名</param>
            /// <param name="strMyPass">发送人密码</param>
            /// <param name="strMySmtp">发送人邮箱Smtp地址</param>
            /// <param name="strToEmail">接收人邮件名</param>
            /// <param name="strSubject">发送主题</param>
            /// <param name="strContent">发送内容</param>
            /// <param name="strIsHTML">是否为html</param>
            /// <param name="strFileArray">发送上传的路径</param>
            public static bool SendEmails(string strMyEmail, string strMyPass, string strMySmtp, List<string> strToEmail, string strSubject, string strContent, bool strIsHTML, string[] strFileArray)
            {
                try
                {
    
                    MailMessage message = new MailMessage();
                    message.From = new MailAddress(strMyEmail);
                    foreach (string item in strToEmail)
                    {
                        message.To.Add(new MailAddress(item));//接收人邮箱
                    }
    
                    //message.To.Add(new MailAddress(strMyEmail));
                    message.Subject = strSubject;//主题
                    message.Body = strContent;//发送内容 
                    message.IsBodyHtml = strIsHTML;
                    if (strFileArray != null)
                    {
                        for (int i = 0; i < strFileArray.Length; i++)
                        {
                            
                            Attachment data = new Attachment(strFileArray[i], MediaTypeNames.Application.Octet);
                            ContentDisposition disposition = data.ContentDisposition;
                            disposition.CreationDate = System.IO.File.GetCreationTime(strFileArray[i]);
                            disposition.ModificationDate = System.IO.File.GetLastWriteTime(strFileArray[i]);
                            disposition.ReadDate = System.IO.File.GetLastAccessTime(strFileArray[i]);
                          
                            message.Attachments.Add(data);
                        }
                    }
                    SmtpClient client = new SmtpClient(strMySmtp, 25);
                    client.Credentials = new System.Net.NetworkCredential(strMyEmail, strMyPass);
                    client.Send(message);
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
    
  • 相关阅读:
    [转载]--python3.6 错误: ModuleNotFoundError:No module named "Crypto"
    [笔记]--RedHat6.5使用CentOS的yum源
    [笔记]--Linux公社,想要的都在里面
    [笔记]--vsftpd配置教程
    Vue 中 axios 配置使用
    Element-ui自定义主题换肤
    vue-cli项目打包需要修改的路径问题
    cookie和session 以及 localStorage和sessionStorage之间的区别和应用场景
    正则表达式
    详解-vue项目中的文件和目录
  • 原文地址:https://www.cnblogs.com/ZJ199012/p/4917819.html
Copyright © 2011-2022 走看看