After sending a few emails: Could not connect to SMTP host, nested exception is: java.net.ConnectException: Connection refused: connect
I want to send all unread emails from server to another email address.
I send each unread email using HostGator.
After sending 30-40 mails an error occurs.
Could not connect to SMTP host, nested exception is: java.net.ConnectException: Connection refused: connect
I checked with smtp port 25, 465, 587. Same error appears.
Email send method:
public static void send(String sub,final String user, final String pass, String toMails) throws Exception {
Properties props = new Properties();
props.put("mail.smtp.host", "gator.hostgator.com");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, pass);
}
});
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(user));
message.addRecipients(Message.RecipientType.TO, toMails);
message.setSubject(sub);
message.setText("-Body-");
BodyPart messageBodyPart1 = new MimeBodyPart();
messageBodyPart1.setText("-Body-");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart1);
message.setContent(multipart);
Transport.send(message);
}
