0
我想通過Java內的電子郵件發送文本消息。通過電子郵件在Java中發送SMS文本錯誤
當我通過Outlook使用以下方法執行此操作時,它工作得非常好。
然而,當我嘗試在使用JavaMail Java中,我得到:
java.mail.SendFailedException:無效地址
Properties props = new Properties();
props.put("mail.smtp.host", "mail.xxxx.org");
props.put("mail.transport.protocol", "smtp");
Session session = Session.getInstance(props, null);
String msgBody = "You have a new message.";
try {
javax.mail.Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("[email protected]", "Email Name"));
msg.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress("[email protected]", "Phone"));
msg.setSubject("New Message.");
msg.setContent(msgBody, "text/plain");
Transport.send(msg);
}
catch (Exception e) {
// ...
}
當我改變行
msg.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress("[email protected]", "Phone"));
到
msg.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress("[email protected]", "Phone"));
它工作正常。
任何幫助或提示將不勝感激。
謝謝。
在[JavaMail FAQ](http://www.oracle.com/technetwork/java/javamail/faq/index.html)中也有Gmail和其他示例。 –