java - 无法通过 SMTP、Java 向海外发送电子邮件
问题描述
我很困惑,陷入了我的项目。
我想通过 SMTP JAVA 向海外电子邮件地址发送电子邮件,但收到超时消息。
我不知道为什么。
我的配置xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com" />
<property name="port" value="25" />
<property name="username" value="testing@gmail.com" />
<property name="password" value="password" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
</props>
</property>
</bean>
<bean id="emailService" class="com.dwidasa.iacssweb.service.feature.EmailService">
<property name="mailSender" ref="mailSender" />
<property name="simpleMailMessage" ref="customeMailMessage" />
</bean>
<bean id="customeMailMessage"
class="org.springframework.mail.SimpleMailMessage">
<property name="subject" value="RESET PASSWORD" />
<property name="text">
<value>
<![CDATA[
Dear %s,
%s
]]>
</value>
</property>
</bean>
</beans>
请帮助我,没有错误,只是连接超时。我很困惑,因为当我在本地服务器上测试时,它成功了。
错误:
造成的:
org.springframework.mail.MailSendException:邮件服务器连接失败;嵌套异常是 javax.mail.MessagingException:无法连接到 SMTP 主机:smtp.dwidasa.com,端口:587;嵌套异常是:java.net.ConnectException: Connection timed out(连接超时)。失败消息:javax.mail.MessagingException:无法连接到 SMTP 主机:smtp.dwidasa.com,端口:587;嵌套异常是:java.net.ConnectException: Connection timed out(连接超时);消息异常详细信息(1)是:
解决方案
尝试使用端口:587 并为 javaMailProperties 添加以下属性
<prop key="mail.transport.protocol">smtp</prop>
推荐阅读
- elasticsearch - 由于我的位置字段未设置为 geo_point,因此未正确输入摄取的数据
- javascript - asp.net mvc 以只读/禁用模式打开视图
- azure - Azure CosmosDB 复制数据库存储过程
- python - 如何在没有for循环的情况下计算numpy数组
- html - CSS Grid Justify-Content 不适用于所有值
- flutter - Flutter:防止一些孩子被拉伸
- c# - if (((row ^ col) & 1) == 0) continue 会怎样?在我的 C# Chessboard App 上下文中的意思
- javascript - 从pdf阅读器中提取文本时如何允许换行?
- php - 如何使 HTML 标题在 PHP 文件中使用 PHP 变量
- javascript - eventClick 未在自定义视图中触发