org.springframework.mail.MailSendException/java.net.ConnectException的可能原因?

org.springframework.mail.MailSendException/java.net.ConnectException的可能原因?,java,spring,email,cloud-foundry,Java,Spring,Email,Cloud Foundry,我有一个Spring Boot应用程序,每天一次,它应该向用户发送一些电子邮件,这些用户需要了解当天发生的一些特定事件。我正在使用它提供的springbootstartermail依赖项和javamailssender 邮件的My application.proiperties配置如下(当然有正确的主机、用户和密码数据): 负责发送邮件的代码是: private void sendMessage(String email, String text, String subject) { t

我有一个Spring Boot应用程序,每天一次,它应该向用户发送一些电子邮件,这些用户需要了解当天发生的一些特定事件。我正在使用它提供的
springbootstartermail
依赖项和
javamailssender

邮件的My application.proiperties配置如下(当然有正确的主机、用户和密码数据):

负责发送邮件的代码是:

private void sendMessage(String email, String text, String subject) {
    try {
        MimeMessage message = javaMailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, true);

        helper.setFrom(SENDER);
        helper.setSubject(subject);
        helper.setTo(email);
        helper.setText(text, true);

        javaMailSender.send(message);

    } catch (MessagingException e) {
        e.printStackTrace();
    } catch (MailException e) {
        e.printStackTrace();
    }
}
其中,
javaMailSender
是自动连接的,并且SENDER总是设置为
spring.mail.username
属性的值。此方法在计划作业内的循环中调用,通常为10到20次(对于应通知的每封电子邮件)

当我在本地机器或公司服务器上运行此应用程序时,它不会出现问题,但当应用程序在pivotal cloud foundry上运行时,它会先发送2到3封电子邮件,然后抛出

org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: myhost.com, 25; timeout -1;
java.net.ConnectException: Connection timed out. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: myhost.com, 25; timeout -1;
...
可能的原因是什么?我试图找到答案,但我能找到的每个描述的问题都与邮件根本不工作有关,通常是由于配置不好,而事实并非如此(我认为),因为我可以成功地从两台不同的机器(都在邮件主机本地网络之外)发送电子邮件但不能从pivotal cloud(或者更具体地说,只能在异常出现之前部分完成)

org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: myhost.com, 25; timeout -1;
java.net.ConnectException: Connection timed out. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: myhost.com, 25; timeout -1;
...