Search code examples
androidoauthsmtpgmail

Android example needed for sending mail via SMTP from oAuth authenticated app


I am following a demo for oAuth that retrieves a users Gmail Contacts. I can authenticate via oAuth and getting the contacts works just fine.

Now I want to modify this to be able to send an email via SMTP. I can get oAuth authorization to do this just fine.

My problem is that I can't figure out the next step. How do I format the request to send an email once I am authenticated.

I don't expect anyone to write the code for me, just a simple link to the google api docs that cover this should get me going. I just can't seem to find them.

Thanks for any help.


Solution

  • I've actually been researching on this too. If you can authenticate via OAuth, then you'll just need Google's API for Gmail via OAuth to get it working. I got Gmail working with OAuth as a java application. For Android though, it's funny that the same code Google provided only works for SMTP (not IMAP). But I guess it'll still help.

    The following link will get you to Google's OAuth protocols for Gmail: https://developers.google.com/google-apps/gmail/oauth_overview They have sample ready to use. Make sure you have JavaMail and the OAuth access token ready. You don't need Apache Ant to run their sample code though. I just used eclipse and ran the main class.

    Also know that OAuth for Gmail is slightly different. I'm not sure how you're doing the authentication, but for Gmail the SCOPE will be different: https://mail.google.com/ In case you don't know about it, Scribe would be an extremely convenient way to get OAuth working in Java.