我们的邮件设置与谷歌应用程序.我们希望能够在传入邮件上运行一些正则表达式并处理此信息.
今天是否可以使用Google App Engine?谷歌提供某种可以做到这一点的基础设施吗?
Gab*_*iel 11
从谷歌文档在这里:
收邮件
您的应用可以通过以下表单的地址接收电子邮件:
string@appid.appspotmail.com
请注意,即使您的应用部署在自定义域中,您的应用也无法接收发送到该域上的地址的电子邮件.电子邮件将作为HTTP请求发送到您的应用.这些请求由App Engine生成并发布到您的应用程序.在应用程序的配置中,指定将被调用以处理这些HTTP请求的处理程序.在处理程序中,您会收到电子邮件的MIME数据,然后将其解析为各个字段.
使用以下URL将电子邮件作为HTTP POST请求发送到您的应用:
/_ah/mail/address
其中address是完整的电子邮件地址,包括域名.默认情况下,禁用在您的应用中接收邮件的功能.要使您的应用程序能够接收邮件,您必须在app.yaml文件中指定您希望启用此服务,方法是:
inbound_services:
- mail
Python SDK定义了InboundMailHandler,这是一个用于处理传入电子邮件的webapp类.要使用InboundMailHandler,您可以将其子类化并覆盖receive()方法.使用类InboundEmailMessage的参数调用receive()方法,这是Python SDK定义的另一个类.
InboundMailHandler位于google.appengine.ext.webapp.mail_handlers包中.您可以像这样创建一个InboundEmailMessage实例:
import logging, email
from google.appengine.ext import webapp 
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler 
from google.appengine.ext.webapp.util import run_wsgi_app
class LogSenderHandler(InboundMailHandler):
    def receive(self, mail_message):
        logging.info("Received a message from: " + mail_message.sender)
InboundEmailMessage对象包含用于访问其他消息字段的属性:
subject contains the message subject.
sender is the sender's email address.
to is a list of the message's primary recipients.
cc contains a list of the cc recipients.
date returns the message date.
attachments is a list of file attachments, possibly empty. Each value in the list is a tuple of two elements: the filename and the file contents.
original is the complete message, including data not exposed by the other fields such as email headers, as a Python email.message.Message.
| 归档时间: | 
 | 
| 查看次数: | 6046 次 | 
| 最近记录: |