0
這是我的code.Can任何人都可以告訴我爲什麼它發送一個電子郵件兩次給單身人士。
我必須只發送一個郵件。我將更改以獲取正確的結果?電子郵件收到兩次,但我只想要一次
public void dbbackup_notify(String email, String data, String subject) {
String toEmails = email;
Session session = Session.getInstance(props, newjavax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, pass);
}
});
Message message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress(userid));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(toEmails));
message.setSubject(subject);
message.setText(data);
message.setContent(data, "text/html");
transport = session.getTransport("smtp");
transport.connect(host, user, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
System.out.println("Sent Successfully: " + new Date());
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
System.out.println("Don't Send Successfully" + new Date());
}
}