zoukankan      html  css  js  c++  java
  • SpringBoot中发送邮件-本地发送成功,部署到阿里云发送不了

    很多次我在本地写好了发送邮件的服务之后,部署到阿里云的服务器,就歇菜了。Google了很久,找到的别人的记录都是差不多。有人提到了使用端口的问题。解决因端口问题而发送不了邮件。

    ​ 我使用的是网易云的邮箱,填好smtp服务器,填好基本的信息,本地一跑。诶,可以发送了。

    依赖pom.xml

    <dependencies>
    	<dependency> 
    	    <groupId>org.springframework.boot</groupId>
    	    <artifactId>spring-boot-starter-mail</artifactId>
    	</dependency> 
    </dependencies>
    

    在application.properties中:

    spring.mail.host=smtp.163.com //邮箱服务器地址
    spring.mail.username=xxx@163.com //用户名
    spring.mail.password=xxyyooo    //密码
    spring.mail.default-encoding=UTF-8
    mail.fromMail.addr=xxx@163.com  //以谁来发送邮件
    

    这个方法具体可以参考博客:SpringBoot发送邮件

    这个方法在本地是没有问题的,但是部署在阿里云上之后,会看到报错,smtp端口25连接超时。。。

    解决

    于是,找了一下原因,发现是阿里云的服务器不能使用25端口。

    现在可以用smtp的465端口来发送邮件,网上的配置也是五花八门,找到一个配置比较全的文章:SpringBoot集成邮箱

    和普通的文章只有配置文件的区别。

    spring:
      mail:
        host: smtp.126.com
        username: xx@126.com
        password: xxxxxxxx
        protocol: smtp
        properties.mail.smtp.auth: true
        properties.mail.smtp.port: 465 #465或者994
        properties.mail.display.sendmail: Javen
        properties.mail.display.sendname: Spring Boot Guide Email
        properties.mail.smtp.starttls.enable: true
        properties.mail.smtp.starttls.required: true
        properties.mail.smtp.ssl.enable: true
        default-encoding: utf-8
        from: xx@126.com
    
  • 相关阅读:
    点集拓扑的重要内容回顾
    Python(二):多进程与多线程
    动态规划(一):笨办法理解动态规划
    PyPI(一):pipreqs获取当前项目依赖包
    Effective python(五):内置模块
    Python(一):装饰器
    基础数学(十一):速算
    Effective python(四):元类及属性
    基础数学(十):计算与公式
    Effective python(三):类与继承
  • 原文地址:https://www.cnblogs.com/to-red/p/13110554.html
Copyright © 2011-2022 走看看