阿里云不能发送邮件总结。发送配置是163邮件

不能发送邮件可能原因:(以下以163邮箱为例,smtp服务器是: smtp.163.com)

1、端口被封,目前阿里云很多25端口被封不能使用。测试方法:

使用Telnet smtp.163.com 25

如果端口正常可以使用25端口发送,否则只能改用465,由于.net 的新方法:System.Net.Mail.StmpClient不能用465端口发,所以如果使用465改用过时的方法  System.Web.Mail.SmtpMail

2、被发件服务器当成垃圾邮件阻止。   解决方法:抄送一份给自己。

 

        /// <summary>
        /// 发送邮箱
        /// </summary>
        /// <param name="emails">发送邮箱</param>
        /// <param name="title">邮件标题</param>
        /// <param name="cPassword">邮件内容</param>
        public static void SendEmailBack(List<string> emails, string title, string content)
        {
            
            string Email_smtp = new BSet("500").cCode2;//发邮件smtp服务器名称              
            string Email = new BSet("510").cCode2; //发送人邮箱地址               
            string Email_smtp_J =new BSet("520").cCode2;//发邮件邮箱授权码 

            WriteLog("Email_smtp:" + Email_smtp);


            System.Web.Mail.MailMessage mmsg = new System.Web.Mail.MailMessage();
            //邮件主题
            mmsg.Subject = title;
            mmsg.BodyFormat = System.Web.Mail.MailFormat.Html;
            //邮件正文
            mmsg.Body = content;
            //正文编码
            mmsg.BodyEncoding = Encoding.UTF8;
            //优先级
            mmsg.Priority = System.Web.Mail.MailPriority.High;
            //发件者邮箱地址
            mmsg.From = Email;
            //收件人收箱地址
            string to ="";
            emails.ForEach(s=>{to+= s+",";});
            if (!string.IsNullOrEmpty(to)){
                to += Email;
            }
            
            //mmsg.To = "th_msc@qq.com";
            mmsg.Cc = to ;

            mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
            //用户名
            mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Email);
            //密码
            mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Email_smtp_J);
            //端口 
            mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);
            //是否ssl
            mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl",true);
            //Smtp服务器
            System.Web.Mail.SmtpMail.SmtpServer = Email_smtp;

            try
            {
                System.Web.Mail.SmtpMail.Send(mmsg);
            }
            catch (SmtpException e)
            {
                WriteLog("发送邮件出错:" + e.ToString());
            }


        }

 

posted @ 2019-04-16 15:27  清风笑  阅读(2629)  评论(0编辑  收藏  举报