我想从服务器获取所有未读电子邮件,并将每封邮件发送到另一封电子邮件。当我发送每封未读电子邮件(使用HostGator)时,在发送几封邮件(30-40)之后,我提到了一个错误。这是我的发送方法。我能做什么?我检查了smtp端口25,465,587。但他们都没有工作。出现相同的错误。 :/如果有人知道如何处理它,请告诉我。谢谢..
电子邮件发送方式: -
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);
}