• 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;
                }
            }
    
  • 相关阅读:
    数据结构_bubble_sort
    数据结构_sfdg(小F打怪)
    数据结构_yjjsj(伊姐姐数字游戏)
    数据结构 queue
    数据结构 Job
    数据结构 happiness
    数据结构_calculator
    js并归排序的思路
    js神秘的电报密码---哈弗曼编码
    js同时获得数组的两个最小值
  • 原文地址:https://www.cnblogs.com/ZJ199012/p/4917819.html
Copyright © 2020-2023  润新知