如何使用MailConnectException解决问题?

时间:2019-06-28 07:16:17

标签: java spring

使用本地主机时,访问公司电子邮件时遇到问题,出现此错误,

[ERROR] com.sun.mail.util.MailConnectException: Couldn't connect to host, port: mail.xitee.com, 25; timeout 5000;

老实说,我不知道为什么会这样。 但是如果我使用服务器,它可以正常工作,这很奇怪。 我认为与该问题有关的唯一原因可能是由于我使用FortiClient连接到公司的服务器。 有谁知道为什么会这样或通常会发生什么情况,以便我进行验证? 当我尝试发送

时会发生问题
 email 
sender.send(message); // here i get the mail MailException

这是一个示例方法:

/**
 * @param email .
 * @param firstName .
 * @param lastName .
 * @throws Exception 
 */
public void sendEmailToActivatedPartner(String email, String firstName, String lastName)
        throws Exception
{
    ResetPasswordRequestDto resetPassword = new ResetPasswordRequestDto();
    resetPassword.setEmail(email);
    String token = resetPasswordService.resetPassword(resetPassword);
    MimeMessage message = sender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message);

    String link = ServletUriComponentsBuilder.fromCurrentContextPath().host(host).port(-1)
            .replacePath("/auth/reset").queryParam("token", token).build().encode().toUriString();

    String linkContact = ServletUriComponentsBuilder.fromCurrentContextPath().host(host).port(-1)
            .replacePath("/auth/contactus").build().encode().toUriString();

    helper.setFrom(new InternetAddress(username)); /// those two line are realeated to the error
    helper.setTo(new InternetAddress(email)); /////// those two line are realeated to the error
    // Translation needs to be done
    helper.setText("<html><body><p>Dear " + firstName + " " + lastName
                   + ", your partner account in the Czech Business Cloud has been activated"
                   + " and you can start selling your applications now."
                   + " Please setup your password via this <a href ='" + link + "'>link.</a>."
                   + " This link is valid for 1 day."
                   + "<p>In case you need support do not hesitate to <a href ='" + linkContact + "'>contact us.</a></p></body><html>",
            true);
    helper.setSubject("CBC - the account is Activated");

    sender.send(message);
}

我收到数据库的这个错误。

org.postgresql.util.PSQLException: This connection has been closed.

感谢您的回答

0 个答案:

没有答案