简体   繁体   中英

Mail service GAE issue - sending mail exception “javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;”

I'd like to send mail from my GAE project. I've followed the documentation example...

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);

    try {
      Message msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress("xxx@xxxx.appspotmail.com", "Example.com Admin"));
      msg.addRecipient(Message.RecipientType.TO,
                       new InternetAddress("xxxxx@gmail.com", "Mr. User"));
      msg.setSubject("Your Example.com account has been activated");
      msg.setText("This is a test");
      Transport.send(msg);
    } catch (AddressException e) {
      e.printStackTrace();
    } catch (MessagingException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}

After deployment, I get this exception message

javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;

But the documentation says that:

When you create a JavaMail Session, if you do not provide any SMTP server configuration, App Engine uses the Mail service for sending messages

But it seems to try connecting to a SMTP server... and obviously there is no SMTP server on localhost...

I've never used this service... my quotas are full available.

Please, help me !

had the same issue today. just got it working. app engine sdk already includes the classes you will need to send email:

https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/mail/MailService.Message

that and the related classes are the way to invoke the mail service. replace your message classes with those, remove all references to javax.mail. one other thing in case you're referencing this (as I was):

https://cloud.google.com/appengine/docs/standard/java/mail/sending-mail-with-mail-api

I couldn't get it to work, doesn't looks like it would without an smtp host at least. Nice of google to provide nonsensical documentation for a non-working example in their example code base

also, if you follow the "who can send mail" link it tells you that any address of the form anything@[APP_NAME].appspotmail.com or anything@[APP_ALIAS].appspotmail.com should work. using my apps name resulted in "unauthorized sender", but using the app id from the dashboard worked. what should have been a ten minute solution turned into hours of drudgery, but I have a working emailer. thanks, google.

The Mail service API supports the JavaMail (javax.mail) interface which is included with the App Engine SDK. Using any other jars may create the issue. You may follow the code sample in Java 7 and Java 8 which demonstrate how to send mail.

I should note that outbound connections on ports 25, 465, and 587 are not allowed due to spam concerns, so the sender address of a message must be one of the optioned in this link .

You can take your application ID/name (which is the same as the project ID/name) through the dashboard.

Kindly note that Issue Tracker is reserved for reporting bugs and feature requests. If you encounter any issue related to APP_NAME or APP_ALIAS, it is recommended to report the issue there so that we would be able to dig into the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM