2015/10/29

[Python][Google App Engine]メール受信 その1

ちょっとメール受信機能がほしかったので、作ってみた。

まずは、app.yamlに下の記述を行う

inbound_services:
- mail
続いて同じapp.yamlに下の記述を行う
- url: /_ah/mail/.+
  script: handle_incoming_email.app
handle_incoming_email.pyファイルに以下の記述を行う
import webapp2
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler

class HogeHandler(InboundMailHandler):
  def receive(self, mail_message):
    #処理を記述

app = webapp2.WSGIApplication([HogeHandler.mapping()], debug=True)
これで
string@appid.appspotmail.com
で記述されたメールを受信することができる。
(stringは、任意の文字列、appidは、google app engineのプロジェクト作成時に作ったappid)

0 コメント:

コメントを投稿