Accessing Gmail account from Google App Engine

天涯浪子 提交于 2019-12-11 10:38:56

问题


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.


回答1:


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




回答2:


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:


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.



来源:https://stackoverflow.com/questions/9446972/accessing-gmail-account-from-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!