尝试连接SMTP主机时,出现此错误SocketException:连接重置

时间:2020-08-05 12:14:24

标签: java smtp gmail jakarta-mail imap

调试SMTP:尝试连接到主机“ smtp.gmail.com”,端口587,isSSL为false 调试SMTP:读取异常响应,抛出: java.net.SocketException:连接重置

void replyToEmail(String subject, String text, String mailFolder = "INBOX",
                      String host = configProvider.getEMAIL_RECIPIENT_HOST(),
                      String user = configProvider.getEMAIL_RECIPIENT_USERNAME(),
                      String password = configProvider.getEMAIL_RECIPIENT_PASSWORD()
    ) {
        Session session = setSessionConfigurationAuth()
        Store store = session.getStore("imaps")
        store.connect(host, user, password)
        // Open mail folder
        Folder folder = store.getFolder(mailFolder)
        folder.open(READ_ONLY)


        String replyText
        if (mimeMessageParser.hasPlainContent()) {
            replyText = mimeMessageParser.plainContent
        } else if (mimeMessageParser.hasHtmlContent()) {
            replyText = mimeMessageParser.htmlContent
        }
        replyMessage.setText("\n$text".concat("\n").concat(replyText))

        // Send out email reply
        Transport t = session.getTransport("smtp")
        try {
            //connect to the smpt server using transport instance

在此处连接失败

            t.connect(user, password)
            t.sendMessage(replyMessage, replyMessage.getAllRecipients())
        } finally {
            t.close()
        }
        log.info('Replied email to ' + receivedMsg.getReplyTo())

        closeEmailConnection(folder, store)
 

}

0 个答案:

没有答案