我發送消息給無效的電子郵件地址,但我沒有得到任何異常。它像一切都很好,在調試器中表現爲一切正常。傳輸sendMessage不會拋出異常
private MailService() {
Properties props = new Properties();
props.put("mail.transport.protocol", "smtps");
props.put("mail.smtps.host", HOST);
props.put("mail.smtps.auth", "true");
props.put("mail.smtp.from", FROM);
props.put("mail.smtps.quitwait", "false");
mailSession = Session.getDefaultInstance(props);
mailSession.setDebug(true);
}
public static void sendMessage(String recipient, String subject,
String message) throws MessagingException {
if (mailService == null) {
mailService = new MailService();
}
MimeMessage mimeMessage = new MimeMessage(mailSession);
mimeMessage.setFrom(new InternetAddress(FROM));
mimeMessage.setSender(new InternetAddress(FROM));
mimeMessage.setSubject(subject);
mimeMessage.setContent(message, "text/plain");
mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient));
Transport transport = mailSession.getTransport("smtps");
transport.connect(HOST, PORT, USER, PASSWORD);
transport.sendMessage(mimeMessage,
mimeMessage.getRecipients(Message.RecipientType.TO));
transport.close();
}
我嘗試了不同的電子郵件地址,併爲所有它沒有拋出異常。我錯了什麼?
什麼*確切*你的意思是「無效」?你能給個例子嗎?例如,沒有郵箱的電子郵件地址與語法無效的電子郵件地址不同。 – 2013-02-11 17:55:25
@Jon Skeet:任何愚蠢的地址,例如:[email protected],我也嘗試從郵件發送郵件,顯然它說無效的電子郵件。 – 2013-02-11 18:01:57