阿里雲服務器發送郵件:Connection could not be established with host smtp.qq.com [Connection timed out #110]


阿里雲服務器發送郵件:Connection could not be established with host smtp.qq.com [Connection timed out #110]

一、總結

一句話總結:

端口號port 改成 465,加密方式 encryption 改用 ssl

 

 

 

二、Connection could not be established with host smtp.163.com

轉自或參考:Connection could not be established with host smtp.163.com 阿星小棧
https://blog.csdn.net/u010244476/article/details/83190154

 

laravel阿里雲屏蔽25,無法發送郵件的解決方案

本地測試郵件可以發送成功,但是部署在阿里雲服務器上之后,並且在安全組中配置了25端口的出入后還是不行。

原因是:

阿里雲服務器封禁了25

解決辦法

  端口號port 改成 465

  加密方式 encryption 改用 ssl

也就是加入了SSL驗證

 

 

 

 

三、laravel中成功配置實例

 

 

 

 

三、阿里雲服務器25郵件端口問題

轉自或參考:阿里雲服務器25郵件端口問題
https://blog.csdn.net/weixin_30780649/article/details/101627176


配置示例:

spring:
  mail:
    host: smtp.163.com
    username: 1111111@163.com
    password: aaaaaaaa
    default-encoding: UTF-8
    properties:
      mail:
        smtp:
          auth: true
          ssl:
            trust: smtp.163.com
          socketFactory:
            class: 'javax.net.ssl.SSLSocketFactory'
            port: 465
          starttls:
            enable: true
            required: true

轉載於:https://www.cnblogs.com/javabg/p/11398950.html

 

四、阿里雲服務器郵件發送

轉自或參考:阿里雲服務器郵件發送
https://www.cnblogs.com/eye-like/p/10103783.html

一個郵件發送的功能,本機調試無問題,但發布到阿里雲服務器后郵件發送功能失敗。

網上查了下大概是說阿里雲把發送郵件的25端口禁用掉了

那么解決方式一就是向阿里雲申請開放25端口,但具體如何申請,並未深入操作。

解決方式二:使用郵件服務商的加密端口。

但是當使用465端口時,先后試驗過smtp.mxhichina.com(阿里企業郵箱)、smtp.163.com(163郵箱)、smtp.qq.com(qq郵箱)三種發送方式,均失敗!

再嘗試考慮SSL加密SMTP通過587端口進行發件,發送成功。

以下為配置及源碼

<?xml version="1.0" encoding="utf-8"?>
<xml>
  <!--收件人郵箱地址-->
  <ConsigneeAddress>pro@163.com</ConsigneeAddress>
  <!--抄送郵箱地址,多個郵箱間用'|'分割-->
  <BccAddress></BccAddress>
  <!--收件人名稱-->
  <ConsigneeName>浦泓醫療</ConsigneeName>
  <!--發件人名稱-->
  <ConsigneeHand>微商城</ConsigneeHand>
  <!--郵件主題-->
  <ConsigneeTheme>睛彩眼界商城訂單</ConsigneeTheme>
  <!--發件郵件服務器的Smtp設置-->
  <SendSetSmtp>smtp.qq.com</SendSetSmtp>
  <!--發件人的郵件-->
  <SendEmail>124@qq.com</SendEmail>
  <!--發件人的郵件密碼-->
  <SendPwd>boblunxyluwdjjbh</SendPwd>
  <!--發件端口號-->
  <port>587</port>
  <!--郵件內容-->
  <SendContent>您有新的訂單消息</SendContent>
  <!--后台管理地址-->
  <serverAddress>http://xxx/admin/login</serverAddress>
</xml>
郵箱配置

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Web;
using System.Xml;

namespace MallServer.Utility
{
    public class emailhelper
    {
        public static bool MailSend(emailpara para)
        {
            try
            {
               
                EmailParameterSet EPSModel = new EmailParameterSet();
                string filepath = System.Web.HttpContext.Current.Server.MapPath("\\Files\\email\\email.xml");
                XmlDocument xml = common.xmlHelper.getXML(filepath);
                string BccAddress = xml.SelectSingleNode("xml").SelectSingleNode("BccAddress").InnerText;//郵件抄送地址
                string portvalue = xml.SelectSingleNode("xml").SelectSingleNode("port").InnerText; //發送郵件的端口
                int port = 587;
                int.TryParse(portvalue, out port);
                string serverAddress= xml.SelectSingleNode("xml").SelectSingleNode("serverAddress").InnerText;//提示跳轉的管理地址
              
                EPSModel.ConsigneeAddress = xml.SelectSingleNode("xml").SelectSingleNode("ConsigneeAddress").InnerText;
                EPSModel.ConsigneeName = xml.SelectSingleNode("xml").SelectSingleNode("ConsigneeName").InnerText;//
                EPSModel.ConsigneeHand = xml.SelectSingleNode("xml").SelectSingleNode("ConsigneeHand").InnerText;//發件人標題
                EPSModel.ConsigneeTheme = xml.SelectSingleNode("xml").SelectSingleNode("ConsigneeTheme").InnerText;//收件人的主題
                EPSModel.SendSetSmtp = xml.SelectSingleNode("xml").SelectSingleNode("SendSetSmtp").InnerText;//發件郵件服務器的Smtp設置
                EPSModel.SendEmail = xml.SelectSingleNode("xml").SelectSingleNode("SendEmail").InnerText;//發件人的郵件
                EPSModel.SendPwd = xml.SelectSingleNode("xml").SelectSingleNode("SendPwd").InnerText;
                EPSModel.SendContent = xml.SelectSingleNode("xml").SelectSingleNode("SendContent").InnerText;

                if (para.ConsigneeTheme != "") {
                    EPSModel.ConsigneeTheme = para.ConsigneeTheme;
                }
                if (para.SendContent != "") {
                    EPSModel.SendContent = para.SendContent+"\r\n查看詳細請登陸 "+serverAddress;           
                }


                //確定smtp服務器端的地址,實列化一個客戶端smtp 
                System.Net.Mail.SmtpClient sendSmtpClient = new System.Net.Mail.SmtpClient(EPSModel.SendSetSmtp);//發件人的郵件服務器地址
                //構造一個發件的人的地址
                System.Net.Mail.MailAddress sendMailAddress = new MailAddress(EPSModel.SendEmail, EPSModel.ConsigneeHand, Encoding.UTF8);//發件人的郵件地址和收件人的標題、編碼

                //構造一個收件的人的地址
                System.Net.Mail.MailAddress consigneeMailAddress = new MailAddress(EPSModel.ConsigneeAddress, EPSModel.ConsigneeName, Encoding.UTF8);//收件人的郵件地址和收件人的名稱 和編碼

                //構造一個Email對象
                System.Net.Mail.MailMessage mailMessage = new MailMessage(sendMailAddress, consigneeMailAddress);//發件地址和收件地址
                if (BccAddress != "")
                {
                    string[] addressArr = BccAddress.Split('|');
                    for (int i = 0; i < addressArr.Length; i++)
                    {
                        mailMessage.Bcc.Add(new MailAddress(addressArr[i]));//添加抄送
                    }
                }

                mailMessage.Subject = EPSModel.ConsigneeTheme;//郵件的主題
                mailMessage.BodyEncoding = Encoding.UTF8;//編碼
                mailMessage.SubjectEncoding = Encoding.UTF8;//編碼
                mailMessage.Body = EPSModel.SendContent;//發件內容
                mailMessage.IsBodyHtml = false;//獲取或者設置指定郵件正文是否為html
               

                //設置郵件信息 (指定如何處理待發的電子郵件)
                sendSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定如何發郵件 是以網絡來發
                sendSmtpClient.EnableSsl = true;//服務器支持安全接連,安全則為true
                sendSmtpClient.Port = port;
                sendSmtpClient.UseDefaultCredentials = true;//是否隨着請求一起發

                //用戶登錄信息
                NetworkCredential myCredential = new NetworkCredential(EPSModel.SendEmail, EPSModel.SendPwd);
                sendSmtpClient.Credentials = myCredential;//登錄
                
                sendSmtpClient.Send(mailMessage);//發郵件
                return true;
            }
            catch (Exception ex)
            {
                //common.CommonMethod.WriteTxt("ex.message:"+ex.Message);
                //common.CommonMethod.WriteTxt("ex.Source:" + ex.Source);
                //common.CommonMethod.WriteTxt("ex.StackTrace:" + ex.StackTrace);
                return false;
            }

        }
    }
}
發郵件

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MallServer.Utility
{
    public class emailpara
    {
        public string ConsigneeTheme { get; set; }
        public string SendContent { get; set; }

    }
}
emailpara

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MallServer.Utility
{
    public class EmailParameterSet
    {
        /// <summary>
        /// 收件人的郵件地址 
        /// </summary>
        public string ConsigneeAddress { get; set; }

        /// <summary>
        /// 收件人的名稱
        /// </summary>
        public string ConsigneeName { get; set; }

        /// <summary>
        /// 收件人標題
        /// </summary>
        public string ConsigneeHand { get; set; }

        /// <summary>
        /// 收件人的主題
        /// </summary>
        public string ConsigneeTheme { get; set; }

        /// <summary>
        /// 發件郵件服務器的Smtp設置
        /// </summary>
        public string SendSetSmtp { get; set; }

        /// <summary>
        /// 發件人的郵件
        /// </summary>
        public string SendEmail { get; set; }

        /// <summary>
        /// 發件人的郵件密碼
        /// </summary>
        public string SendPwd { get; set; }
        /// <summary>
        /// 發件內容
        /// </summary>
        public string SendContent { get; set; }
    }
}
EmailParameterSet

 

 

說明:

實例中使用的是qq郵箱,但郵箱的密匙非qq的密碼,而是郵箱的獨立密碼,可以進入qq郵箱,然后在設置-》賬戶里面設置

並且要保證郵箱的POP3/SMTP服務開啟,同樣是進入qq郵箱,然后在設置-》賬戶里面設置

 

引用:

https://www.cnblogs.com/axinno1/p/8303130.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM