Ich versuche, eine Mail mit Zoho SMTP-Server mit dem folgenden Code senden Sie eine Mail mit zoho SMTP-Server zu senden:kann nicht
public void sendEmail(Email email) {
Properties props = setupMailEnv();
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("[email protected]", "xxxxx");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(email.getFromMailId()));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(email.getToEmailId()));
message.setSubject(email.getSubject());
message.setText(email.getBody());
Transport.send(message);
log.info("Mail Sent.");
} catch (MessagingException e) {
throw e;
}
}
private Properties setupMailEnv() {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.zoho.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.startssl.enable", "true");
props.put("mail.smtp.starttls.enable", "false");
return props;
}
Wenn ich dieses Programm ausführen es die folgende Ausnahme geben:
javax.mail.MessagingException: Can't send command to SMTP host;
nested exception is:
java.net.SocketException: Connection closed by remote host
Ich habe Zoho Foren verwiesen, aber keiner von ihnen gab die Lösung. Wie kann ich dieses Problem beheben?
Doppelte Ausgabe https://Stackoverflow.com/questions/6740838/javamail-issue-cant-send-command-to-smtp-host – apm