有什么方法可以在不连接和断开邮件服务的情况下应用此循环?该循环对于 2 或 5 人工作正常,但何时达到 100 人将需要很长时间才能发送所有消息。每个循环大约需要 3 秒。
while(rs.next()){
items = rs.getString("email");
try {
Properties mail = new Properties();
mail.setProperty("mail.smtp.host", "smtp.gmail.com");
mail.setProperty("mail.smtp.starttls.enable","true");
mail.setProperty("mail.smtp.port", "25");
mail.setProperty("mail.smtp.user", "cuatrocuadrado@gmail.com" );
mail.setProperty("mail.smtp.auth", "true");
session=Session.getDefaultInstance(mail);
message= new MimeMessage(session);
message.setFrom(new InternetAddress("cuatrocuadrado@gmail.com"));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(items));
//message.addRecipient(Message.RecipientType.BCC, new InternetAddress());
message.setSubject(Email.tSubject.getText());
message.setText(Email.areaEmail.getText());
Transport t = session.getTransport("smtp");
t.connect("cuatrocuadrado@gmail.com","*********");
t.sendMessage(message, message.getAllRecipients());
t.close();
} catch (MessagingException ex) {
JOptionPane.showMessageDialog(null,ex.getMessage());
}
} } catch (SQLException ex) {
Logger.getLogger(SendEmail.class.getName()).log(Level.SEVERE, null, ex);
}JOptionPane.showMessageDialog(null,"Success");