eddyparkinson
eddyparkinson

Reputation: 3700

GAE send email from gmail account

How can I send email from a Gmail account using Google-App-Engine? The sender address is the problem, this is understandably restricted because of spam. (Restrictions are here: https://developers.google.com/appengine/docs/java/mail/usingjavamail#Senders_and_Recipients )

Aim: I want users to come to the web site, register to use the service (via OAuth). And the service will be able to send email with the "sender address" set to the users email address. (Service: spreadsheet formula that sends email)

Related question: Accessing Gmail account from Google App Engine

Options:

1) Avoid JavaMail: Email via HTTP looks like it would work for a small fee. Could use: Amazon SES aws.amazon.com/ses/

not possible 2) contextIO - some people have suggested contextIO. Update: does not send email, see http://context.io/docs/2.0

3) OAuth - it looks like you can use OpenID and send email as the current logged in user. So maybe offline sending with OAuth is possible. (Users API https://developers.google.com/appengine/docs/java/users/)

4) sender verification - (Only usable to test things out, not a production quality solution) App Engine has "Invite a user to collaborate on this application" as viewer. Maybe there is a API for adding collaborators.

Picked 5) Sockets/SMTP trial - (authenticated SMTP only) in Sep 2012 google posted http://googleappengine.blogspot.com.au/2012_09_01_archive.html

Upvotes: 2

Views: 1325

Answers (4)

Martin V.
Martin V.

Reputation: 3710

We ended up to use external Amazon SES service for emails as Google limited us - in "from:" field was allowed only app admin email address. We tried to switch DKIM or SPF records but this did not helped us, google is very strict in this.

Upvotes: 1

Peter Knego
Peter Knego

Reputation: 80340

In a nutshell - you will not be able to do that via OAuth. The main reason is that it's generally imposible to (reliably, continuously) send mails in volume on behalf of random users, i.e. users that are not on the domain that you control.

  1. If you use OAuth than you will need to ask for access to users profile/email during OAuth procedure. This varies from provider to provider. Some providers never make email available (Twitter). See pac4j library that provides unified API to retrieve user's OAuth profile from different providers.

  2. When (and if) you get email adress from OAuth, than you will need to send email on behalf of that user. Since your SMTP server is not authorised to send emails on behalf of random users (see SPF and DKIM) you will quickly get on spam lists and be blocked. If this was easy then spammers would have easy life.

  3. You can send email on users behalf from AppEngine, but only if users log in via Users Java API, which is only available to Gmail or Google Apps accounts.

  4. On GAE you can easily use external SMPT server, via the new Outbound Sockets API (this just went from trusted tester feature to experimental feature in sdk 1.7.7). We have this setup and it works with no problem, using a large external SMTP service. But this does not help much with what you want to achieve, considering the point 2 above.

Upvotes: 1

koma
koma

Reputation: 6566

The good news is that with the arrival of GAE SDK 1.7.7 it will be possible to talk directly to IMAP and SMTP, see the blog post http://googleappengine.blogspot.be/2013/04/app-engine-177-released.html

The critical new feature (in preview) is "Outbound sockets"

Upvotes: 2

Patrick Simpson
Patrick Simpson

Reputation: 554

I have not tried this on production, but I've set up the GAE dev server to bypass google's mail system and talk to an SMTP server directly. See my answer on another question. If you can do this on production, all you'll need is an SMTP server somewhere that will send your emails.

Upvotes: 1

Related Questions