在googel应用引擎中,如果我们不使用OpenID登录,我们可以发送邮件就像它用API写的一样。
但我使用OpenId登录(使用谷歌邮件),我不能使用这个。
但我做的事就像thatL
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");
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
"mail@gmail.com", "pass");
}
});
**Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("mail"));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("mail"));
message.setSubject("Testing Subject");
message.setText(msgBody);
Transport.send(message);--如果我要登录,然后调用SERVLET,例如www.example.apppot.com/mail--它可以工作!但是如果我没有登录,它就不工作了!,但是我不知道会发生什么?!**
java.lang.RuntimeException: javax.mail.SendFailedException: Send failure (javax.mail.MessagingException: Illegal Arguments (java.lang.IllegalArgumentException: Unauthorized Sender: Unauthorized sender))
at test.queue.MailServlet.sendMail(MailServlet.java:208)在这208行,我有:
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("example@gmail.com","pass");
}发布于 2013-10-09 20:31:12
在" from“中设置的地址应该在gae应用程序的接纳->权限下存在,并且对于从这个允许的帐户发送电子邮件,不需要在代码中指定密码。
“出于安全考虑,邮件的发件人地址必须是应用程序管理员的电子邮件地址或应用程序的任何有效电子邮件接收地址(请参见接收邮件)。如果用户的帐户是Gmail帐户或位于由Google应用程序管理的域,发件人也可以是登录的当前用户的Google帐户电子邮件地址。”--如本文API接口所述。
https://stackoverflow.com/questions/19277840
复制相似问题