Java 通过Spring发送imap邮件服务器的邮件?

Java 通过Spring发送imap邮件服务器的邮件?,java,spring,mail-sender,Java,Spring,Mail Sender,Hi-im使用Spring框架发送邮件。我不知道邮件服务器的设置。我们正在使用mozilla thunderbird。我在春季编写了一个邮件发送应用程序示例。我通过谷歌搜索得出结论,我们需要一个服务器主机和端口。我已经设置了所有这些,但我的问题是它得到以下异常 Exception in thread "main" org.springframework.mail.MailSendException: Mail server connection failed; nested exception

Hi-im使用Spring框架发送邮件。我不知道邮件服务器的设置。我们正在使用mozilla thunderbird。我在春季编写了一个邮件发送应用程序示例。我通过谷歌搜索得出结论,我们需要一个服务器主机和端口。我已经设置了所有这些,但我的问题是它得到以下异常

Exception in thread "main" org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: mail.supremecluster.com, port: 143, response: -1
    at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:418)
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:307)
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:297)
    at com.javacodegeeks.spring.mail.MailService.sendMail(MailService.java:24)
    at com.javacodegeeks.spring.mail.MailServiceTest.main(MailServiceTest.java:14)
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: mail.supremecluster.com, port: 143, response: -1
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1694)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:525)
    at javax.mail.Service.connect(Service.java:291)
    at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:388)
    ... 4 more
Spring.xml

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="host" value="mail.supremecluster.com" />
    <property name="port" value="143" />
    <property name="username" value="myusername@host.com" />
    <property name="password" value="*********" />
    <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>
邮件测试

public static void main(String[] args) {

        ApplicationContext context = new FileSystemXmlApplicationContext("conf/spring.xml");

        MailService mailService = (MailService) context.getBean("mailService");

        mailService.sendMail("myusername@host.com", "myuser@gmail.com",
                "Testing123", "Testing only \n\n Hello Spring Email Sender");

        mailService.sendAlertMail("Exception occurred");

    }

谁能告诉我解决办法吗?谢谢

看来Java无法连接到SMTP服务器mail.supremecluster.com:143

我猜您提供的邮件设置不是SMTP的设置(SMTP仅用于发送电子邮件,IMAP用于接收邮件)。
为什么不打开Thunderbird并在“帐户设置”下检查并查看传出服务器(SMTP)项目中的设置。

我已检查Thunderbird传出设置。服务器名称相同,但传出设置中的端口号不同。现在更改端口后出现以下错误。线程“main”org.springframework.mail.MailSendException中出现异常:邮件服务器连接失败;嵌套异常为javax.mail.MessaginException:无法将套接字转换为TLS`使用与代码中传出服务器中的设置完全相同的设置。出现以下错误:
线程“main”org.springframework.mail.MailSendException中的异常:邮件服务器连接失败;嵌套异常为javax.mail.MessaginException:无法将套接字转换为TLS尝试将属性mail.smtp.starttls.enable设置为trueYour right,我没有看到。我猜服务器不接受TLS安全连接。如果将设置设置为false,会发生什么情况?
public static void main(String[] args) {

        ApplicationContext context = new FileSystemXmlApplicationContext("conf/spring.xml");

        MailService mailService = (MailService) context.getBean("mailService");

        mailService.sendMail("myusername@host.com", "myuser@gmail.com",
                "Testing123", "Testing only \n\n Hello Spring Email Sender");

        mailService.sendAlertMail("Exception occurred");

    }