I use mandrill to send mails. Port is set to 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);
And I am sure that all setting are valid.
Then I set authenticator
authenticator = new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(settings.username, settings.password);
}
};
And sfter that send mail
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;
}
Debug says that I send mail on 25th port
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
I tried to create "smtps" transport, but that didn't help. Mandrill says that I can use port 2525 (or 587, and other). I also send on port 2525 using postfix from linux server with same credentials.
The error is quite stupid)
props.put("mail.smtp.port", settings.port);
in this line port is an int
value, when I changed port
field to String
it started working.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.