簡體   English   中英

為什么javax.mail端口從2525更改為25

[英]Why javax.mail port changed from 2525 to 25

我使用山d發送郵件。 端口設置為2525

props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
//props.put("mail.smtp.**ssl.enable", "true");
//props.put("mail.smtp.**ssl.required", "true");
props.put("mail.smtp.host", settings.host);
props.put("mail.smtp.port", settings.port);

而且我確信所有設置都是有效的。

然后我設置身份驗證器

authenticator = new javax.mail.Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(settings.username, settings.password);
    }
};

然后發送郵件

Session session = Session.getInstance(props, authenticator);
session.setDebug(true);
try {
    Message message = mail.getMessage(session); 
    Transport.send(message);
    System.out.println("Done");
    return true;
} catch (MessagingException e) {
    e.printStackTrace(System.err);
    return false;
}

調試說我在25號端口上發送郵件

DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.s
mtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.mandrillapp.com", port 25, isSSL fal
se
220 smtp.mandrillapp.com ESMTP
DEBUG SMTP: connected to host "smtp.mandrillapp.com", port: 25

我嘗試創建“ smtps”傳輸,但這沒有幫助。 Mandrill說我可以使用端口2525(或587等)。 我還使用具有相同憑據的Linux服務器上的后綴在端口2525上發送。

錯誤是很愚蠢的)

props.put("mail.smtp.port", settings.port);

在此行中,port是一個int值,當我將port字段更改為String它開始工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM