我正在使用 java 邮件 API,它在本地机器上运行良好,但是当我在服务器上部署我的 web 应用程序时,我收到一个异常,说 javax.mail.MessagingException:无法确定本地电子邮件地址。
这是我的代码
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
try {
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("fromEmailAdd@gmail.com", "fromEmailPass");
}
});
MimeMessage message = new MimeMessage(session);
message.addRecipient(Message.RecipientType.TO, new InternetAddress("to@gmail.com"));
message.setSubject("sub");
message.setText("msg");
Transport.send(message);
System.out.println("mail sent successfully");
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
下面给出的是此代码抛出的异常。
javax.mail.MessagingException:无法确定本地电子邮件地址
明月笑刀无情
aluckdog
相关分类