我试图限制收到的电子邮件到我的应用程序,因此它只接受来自谷歌组成员的邮件。更具体地说,我想只将电子邮件的内容添加到我的数据存储区(如果它们是该组的一部分)。我在这里找到了hasMember / IsMember方法:https://developers.google.com/admin-sdk/directory/v1/reference/members/hasMember并且认为这可能是我正在寻找的,但我不知道如何使用它,因为他们还没有提供一个例子,我和我#39;对此我很陌生。
这是否是适用于此的正确API?这是我的传入邮件处理程序代码,我添加了IF语句注释以显示我想要执行的操作:
import webapp2
import logging
from google.appengine.ext.webapp import mail_handlers
from google.appengine.api import mail
import os
from main import WorkRequest
import re
class IncomingMailHandler(mail_handlers.InboundMailHandler):
def receive(self, message):
(encoding, payload) = list(message.bodies(content_type='text/plain'))[0]
body_text = payload.decode()
logging.info('Received email message from %s, subject "%s": %s' %
(message.sender, message.subject, body_text))
logging.info (message.sender)
logging.info(message.subject)
logging.info(body_text)
#IF MESSAGE_SENDER == MEMBER OF GOOGLE GROUP:
wr = WorkRequest()
wr.email = message.sender
wr.userId = None
wr.title = message.subject
wr.content = body_text
wr.status = "OPEN"
wr.submission_type = "EMAIL"
wr.assigned_to = "UNASSIGNED"
wr.put()
application = webapp2.WSGIApplication([('/_ah/mail/.+', IncomingMailHandler)],debug=True)