java.net.SocketException: Connection closed by remote host
Hi,
Iam trying to send an email from zoho to gmail , using java mail api. Am getting the error and my code is as follows.
final String username = "
xxxxxx@novelirs.com";
final String password = "xxxxxxx";
Properties props = new Properties();
props.setProperty("mail.smtp.host", "smtp.zoho.com");
props.setProperty("mail.smtp.port", "587");
props.setProperty("mail.smtp.starttls.enable", "true");
props.setProperty("mail.smtp.auth", "true");
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc));
message.setRecipients(Message.RecipientType.BCC,InternetAddress.parse(bcc));
message.setSubject(subject);
message.setContent(body, "text/html");
Transport.send(message);