1

在 googel 应用引擎中,如果我们不使用 OpenID 登录,我们可以发送邮件,就像它用 API 编写的一样

但我使用 OpenId 登录(使用谷歌邮件),我不能使用它。

但我会做这样的事情L

        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.appspot.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");
        }
4

1 回答 1

2

在“发件人”中设置的地址应该出现在 Gae 应用程序的准入 -> 权限下,并且从这个允许的帐户发送电子邮件,无需在代码中指定密码。

“出于安全考虑,邮件的发件人地址必须是应用程序管理员的电子邮件地址或应用程序的任何有效电子邮件接收地址(请参阅接收邮件)。发件人也可以是当前的 Google 帐户电子邮件地址已登录的用户,如果用户的帐户是 Gmail 帐户或位于由 Google Apps 管理的域中。” - 如此处所述https://developers.google.com/appengine/docs/java/mail/#Java_Sending_mail_with_the_JavaMail_API

于 2013-10-09T20:31:12.960 回答