Receiving Mailについてのチュートリアルを読んでいます。私も、私は、電子メールの送信を実施するために使用hw.py
を持っているGoogle App Engineでメールを受信
application: hello-1-world
version: 1
runtime: python
api_version: 1
handlers:
- url: /favicon.ico
static_files: static/images/favicon.ico
upload: static/images/favicon.ico
- url: /_ah/mail/.+
script: handle_incoming_email.py
login: admin
- url: /.*
script: hw.py
inbound_services:
- mail
をそしてhandle_incoming_email.py
import cgi
import os
import logging
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.api import mail
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
class ReceiveEmail(InboundMailHandler):
def receive(self,message):
logging.info("Received email from %s" % message.sender)
plaintext = message.bodies(content_type='text/plain')
for text in plaintext:
txtmsg = ""
txtmsg = text[1].decode()
logging.info("Body is %s" % txtmsg)
self.response.out.write(txtmsg)
application = webapp.WSGIApplication([
ReceiveEmail.mapping()
], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
を作成しました:私は指示通りのapp.yamlファイルを更新しました。それが動作します。
は今、私はhttp://localhost:8081/_ah/admin/inboundmail
に行くと[email protected]
にメールを送って誰もが、私はこのメールを処理する方法を私に説明できますか?メールの内容にアクセスするにはどうすればよいですか?コードを持っています
self.response.out.write(txtmsg)
handle_incoming_email.py
でも、何も印刷されません。
電子メールの受信方法を明確にしていただければ幸いです。例えば
class MailHandler (InboundMailHandler):
def receive(self, message):
sender = message.sender
user_account = db.GqlQuery("SELECT * FROM Task WHERE user = :1", sender).fetch(5)
は、私の知る限りsender
理解し、送信者のメールです。だから、私の場合、どのように私は送信者の電子メールアドレスにアクセスするのですか?
また、受信メールを処理するために別のスクリプトを用意する必要があるのはなぜですか? スクリプトにReceiveEmail
ハンドラを挿入できないのはなぜですか?私はライン
application = webapp.WSGIApplication([
ReceiveEmail.mapping()
], debug=True)
を入れない場合は、それを行う場合は、これらの質問で私を助けることができる場合、私は感謝されます。
(GAEグループ内I asked the same questionが、何の答えはありませんでした。)
これはlogging.info( "%s"%message.senderからの電子メールを受信しました)のコード行です。 – systempuntoout
はい。私は、logging.infoがログコンソールに情報を記録していることを知らなかった:)そう、コードは動作しているようだ。今私は電子メールの内容をデータストアに書き込む方法を理解する必要があります。ありがとう! – Zeynel