2010-04-24 24 views
1
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, message): 
     _subject = message.subject 
     _sender=message.sender 
     bodies = message.bodies('text/plain') 
     allBodies = "" 
     #for body in bodies: 
     # allBodies = allBodies + "\n---------------------------\n" + body[1].decode() 
     #m= mail.EmailMessage(sender="[email protected] ",subject="reply to "+_subject) 
     #m.to = _sender 
     #m.body =allBodies 
     #m.send() 
     message = mail.EmailMessage(sender="[email protected]", 
             subject="Your account has been approved") 
     message.to = _sender 
     message.body = """ 
     Dear Albert: 

     Your example.com account has been approved. You can now visit 
     http://www.example.com/ and sign in using your Google Account to 
     access new features. 

     Please let us know if you have any questions. 

     The example.com Team 
     """ 

     message.send() 



application = webapp.WSGIApplication([LogSenderHandler.mapping()], debug=True) 

的app.yaml:這是我接收電子郵件的代碼,但不能接收電子郵件。(谷歌應用程序引擎)

application: zjm1126 

version: 1-2 
runtime: python 
api_version: 1 

inbound_services: 
- mail 

handlers: 
- url: /media 
    static_dir: media 

- url: /_ah/mail/.+ 
    script: handle_incoming_email.py 
    login: admin 

- url:/
    script: a.py 

- url: /sign 
    script: a.py 

- url: .* 
    script: django_bootstrap.py 

我用我的電子郵件:發送[email protected]一些詞[email protected]

我無法得到接收電子郵件,爲什麼?

回答

1

它看起來像你試圖使郵件send\receive tutorial的代碼工作。我還使用該教程來檢查郵件服務是如何工作的並且沒有問題。我可以建議做的是:

  1. 解耦郵件發送和接收 腳本,因爲它看起來像你要去 循環它;

  2. 我想你已經有 發送代碼別的地方,但 以防萬一,有東西送 電子郵件至 [email protected]到 觸發LogSenderHandler處理程序;

  3. 您可以使用zjm1126 development 控制檯在本地檢查和調試您的代碼 。嘗試從 發送電子郵件這裏: http://localhost:8080/_ah/admin/inboundmail 將斷點設置成 LogSenderHandler.receive方法 看它是否被擊中,什麼是後所要 ;

  4. 在你的yaml中,我看到了其他的處理程序,但webapp.WSGIApplication只有LogSenderHandler映射。這可能是其他腳本未被執行的原因;

比你的代碼和YAML看起來不錯,應該努力

希望這可以幫助其他的,視

0

一切看起來很好 - 你的處理器返回一個200 OK。如果您沒有收到它發送的電子郵件,請嘗試記錄您使用的值,以便檢查一切是否有效以及您期望的結果。

3

我在遵循google教程後也遇到同樣的問題。感謝this tute,我發現了一個相當重要的代碼,讓我的思想滑落了,不在Google教程中。

def main(): 
    run_wsgi_app(application) 
if __name__ == "__main__": 
    main() 

希望有幫助。

相關問題