• 发邮件,多个附件


     /// <summary>
            ///  发送邮件,提供调用
            /// </summary>
            /// <param name="strSendToList">收件人,多个收件人用做好事隔开</param>
            /// <param name="strSubject">主题</param>
            /// <param name="strBody">内容</param>
            /// <param name="strAttachmentsPath">附件路径</param>
            /// <param name="strOutErr">错误信息</param>
            /// <returns></returns>
            public bool SendMail(string strSendToList, string strSubject, string strBody, string[] arrAttachmentsPath, out string strOutErr)
            {
                //发送邮件服务器
                string strHost = System.Configuration.ConfigurationManager.AppSettings["MailHost"].ToString();
                //发件人地址
                string strUserMail = System.Configuration.ConfigurationManager.AppSettings["MailSender"].ToString();
                //发件人密码
                string strUserPwd = System.Configuration.ConfigurationManager.AppSettings["MailSenderPwd"].ToString();           
                string ss = string.Empty;
                return SendMail(strHost, strUserMail, strUserPwd, strSendToList, strSubject, strBody, arrAttachmentsPath,out strOutErr);
           
            }
    
            /// <summary>
            /// 发邮件
            /// </summary>
            /// <param name="strMailService">邮箱服务器</param>
            /// <param name="strSendMail">发件人邮箱</param>
            /// <param name="strSendMailPwd">发件人密码</param>
            /// <param name="strToList">收件人,多个收件人用做好事隔开</param>
            /// <param name="strSubject">主题</param>
            /// <param name="strMessage">邮件内容</param>
            /// <param name="AttachFile">附件路径</param>
            public bool SendMail(string strMailService, string strSendMail, string strSendMailPwd, string strToList, string strSubject, string strMessage, string[] AttachFile, out string strOutErr)
            {
                System.Net.Mail.SmtpClient client = new SmtpClient(strMailService);
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential(strSendMail, strSendMailPwd);
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(strSendMail, strToList);
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.Subject = strSubject;
                message.Body = strMessage;
                message.IsBodyHtml = true;
                //在有附件的情况下添加附件
                if (AttachFile != null && AttachFile.Length > 0)
                {
                    foreach (string path in AttachFile)
                    {
                        var attachFile = new Attachment(path);
                        message.Attachments.Add(attachFile);
                    }
                }
                try
                {
                    client.Send(message);
                    strOutErr = string.Empty;
                }
                catch (Exception err)
                {
                    strOutErr = err.Message;
                    return false;
                }
                return true;
            }
  • 相关阅读:
    验证车牌警车能源车
    两个二维数组组合并且日期相同的其他值相加
    运用phpExcel导出查询的数据
    JQ加减乘除运算
    获取url传递的参数、鼠标滚动加载事件
    SQL查询将数据按字段(2017-08-15 11:34:05)进行按月分组
    关于角色和权限控制数据表相关
    有关无限极分类并排序问题
    前端解决用户登录时,禁止chrome提示用户保存密码
    前端学习之iframe配合hash做菜单导航的问题:修改src跳转与contentWindow.location.replace('')的问题
  • 原文地址:https://www.cnblogs.com/xbding/p/11303114.html
Copyright © 2020-2023  润新知