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和其他示例。 –