Sending emails via external SMTP server

490 views
Skip to first unread message

Antonio Bucciol

unread,
May 4, 2017, 3:58:50 AM5/4/17
to Google App Engine
Hi,

I'm trying to send emails from Google App Engine Standard in Java by directly connecting to an external SMTP server.
I'm failing doing so.

I can successfully send emails via GAE smtp replay - this is how I accomplish so:
Properties props = new Properties();
props
.put("mail.transport.protocol", "smtp");
Session mailsession = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(mailsession);
[SNIPPET - setting msg parameters]
Transport.send(msg);

In order to send email using an external SMTP server, I've tried to edit the code above adding the following rows:
            props.put("mail.transport.protocol", "smtp");
            props
.put("mail.smtp.host", SRV_IP);  // i.e., SRV_IP="123.123.123.123"
            props
.put("mail.smtp.auth", false);
            props
.put("mail.smtp.port", SRV_PORT);  // i.e, SRV_PORT=9087
 
but looks like such parameters are simply ignored - and the email gets sent using the GAE internal SMTP relay. (edited)

Does anyone know how to accomplish such goal?
Thank you in advance!

George (Cloud Platform Support)

unread,
May 4, 2017, 10:11:21 AM5/4/17
to Google App Engine
Hello Antonio, 

Your use case might be viewed by some as seldom occurring: you want to send email using an external server, when the facility is already provided in the standard environment, as described in the "Mail API Overview" on-line document

One might think of sockets, but "Port 25 (SMTP) is blocked" as indicated in the "Overview of Sockets API for Java" document

Antonio Bucciol

unread,
May 4, 2017, 10:40:05 AM5/4/17
to Google App Engine
Hi George,

thank you for your answer.

I know the mailing facility is provided, but is limited in the amount of daily recipients. For other projects we used to request to raise such limit.
Since this year, GCloud support told us they are not fulfilling new requests for raising such limit anymore.
We were told to use a third-party service, like SendGrid, and that's what I did. But the emails we send via such service, though they are DKIM-certified, they are not DMARC-certified.

So we thought to send emails to a private SMTP relay that is authenticated as a valid relay for our domain, thus sending emails that are both DKIM and DMARC-certified.
Currently, as per your answer, I think the only way we might accomplish this is via sockets. Not so happy to deal with them though.

If you have something to add (or to remove) to such idea, it would be great to hear from you.

Antonio

George (Cloud Platform Support)

unread,
May 4, 2017, 11:21:55 AM5/4/17
to Google App Engine
You may choose to use other similar mailing services that can become DMARC-certified, such as Amazon SES. There are various solutions available, otherwise. 

This discussion group is oriented more towards opinions, trends and issues of general nature touching the app engine. For coding and programming architecture, you may be better served in a forum such as stackoverflow, where experienced programmers are within reach and ready to help. 
Reply all
Reply to author
Forward
0 new messages