Can't send email overseas via SMTP, Java

与世无争的帅哥 提交于 2019-12-11 15:14:44

问题


I'm confused and stuck in my project.

I want to send email via SMTP JAVA to an overseas email address, but I'm getting a timeout message.

I don't know why.

My configuration 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>

Please help me, there is no error, just a connection timeout. I'm confused because when I tested on a local server, it succeeded.

Error:

Caused by:

org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.dwidasa.com, port: 587; nested exception is: java.net.ConnectException: Connection timed out (Connection timed out). Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.dwidasa.com, port: 587; nested exception is: java.net.ConnectException: Connection timed out (Connection timed out); message exception details (1) are:


回答1:


Try using port: 587 and Add following properties for javaMailProperties

<prop key="mail.transport.protocol">smtp</prop>


来源:https://stackoverflow.com/questions/55235720/cant-send-email-overseas-via-smtp-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!