Accessing Gmail account from Google App Engine

2019-08-02 05:41发布

I built an IMAP client using this library:

Gmail IMAP and SMTP using OAuth - Libraries and Samples http://code.google.com/apis/gmail/oauth/code.html

I need to search all the emails in the Inbox and return only those emails matching with my "subject" and which are sent in last 24hrs. Once i have that email i want to read the body and do some processing. I was able to do all of this using above library but when i deploy this code on GAE it fails with with "Security violation" as my code is trying to set some of the following system properties:

props.put("mail.imaps.sasl.enable", "true");
props.put("mail.imaps.sasl.mechanisms", "XOAUTH");
props.put(XoauthSaslClientFactory.OAUTH_TOKEN_PROP, oauthToken);

What are my other alternatives to achieve this task? Few people were talking about RSS feed. Can we achieve what i am looking for using this technique? Any inputs will be appreciated.

Thank You.

3条回答
小情绪 Triste *
2楼-- · 2019-08-02 06:20

Google App Engine only allows http/s communication thru the urlfetch API.
IMAP cannot be used on the production servers.
You can try using urlfetch using GMail built in RSS feed (https://USERNAME%3aPASSWORD@gmail.google.com/gmail/feed/atom).

查看更多
爷、活的狠高调
3楼-- · 2019-08-02 06:31

You can use Google Apps script to access your inbox and send the result to App Engine. http://code.google.com/googleapps/appsscript/service_gmail.html F.I. I use Apps Script with Google Spreadsheets to make reports, based on data in GAE, using a hmac signature to authenticate.

查看更多
淡お忘
4楼-- · 2019-08-02 06:45

I've heard that ContextIO is providing APIs to access GMAIL account. I've tested to get all contacts, emails, files, email's body successfully. The APIs are quite easy to use. You need some steps to obtain ContextIO's Consumer Keys.

They's also providing an API to fetch mails from Google App Engine. Currently, I'm working to bring a demo and hopefully will update this answer soon. However, it's very straight forward and interesting to do :)

App Engine Blogs
Context IO's site

Hope it helps

查看更多
登录 后发表回答