嘿,我对使用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="587" />
<property name="username" value="username@gmail.com" />
<property name="password" value="pass" />
<property name="javaMailProperties">
<props>
<prop key="mail.transport.protocol">smtp</prop>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.debug">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>
错误是:
2019-03-20 16:11:42.151:WARN:oejs.ServletHandler: org.springframework.web.util.NestedServletException:请求 处理失败;嵌套异常为 org.springframework.mail.MailSendException:邮件服务器连接 失败嵌套的异常是javax.mail.MessagingException:无法 连接到SMTP主机:smtp.gmail.com,端口:587; |嵌套异常 是:|?java.net.ConnectException:连接超时(连接超时 出来)。失败消息:javax.mail.MessagingException:无法 连接到SMTP主机:smtp.gmail.com,端口:587; |嵌套异常 是:|?java.net.ConnectException:连接超时(连接超时 出);消息异常(1)是:|失败消息1: javax.mail.MessagingException:无法连接到SMTP主机: smtp.gmail.com,端口:587; |嵌套异常 是:|?java.net.ConnectException:连接超时(连接超时 出)
将源代码移至其他服务器时会发生这种情况。当我在localhost中测试时,没有错误。但是,当我将其移至国外的服务器时,会出现诸如“连接超时”之类的错误。 有人可以帮我解决这个问题吗? 拜托。