我向无效的电子邮件地址发送消息,但我没有收到任何异常。它就像一切都很好,在调试器中它显示一切正常。
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();
}
我尝试了不同的电子邮件地址,但它并没有抛出异常。我错了什么?