0

我有一個使用純python的google終端項目,我使用內置的mail來發送電子郵件。但由於某些原因,電子郵件不會到達接收方(配額未用盡)。所以我想創建一個反彈通知器。迄今爲止我已經完是否有可能接收谷歌應用程序引擎的電子郵件反彈通知 - 蟒蛇?

的app.yaml

inbound_services: 
- mail_bounce 
handlers: 
- url: /_ah/bounce 
    script: applications.APPLICATION 
    login: admin 

applications.py

from app.api.bounce.api import Bounce 

APPLICATION = endpoints.api_server([Bounce]) 

bounce.py

import endpoints 
import logging 

from protorpc import remote, message_types 

from google.appengine.ext.webapp.mail_handlers import BounceNotification 
from google.appengine.ext.webapp.mail_handlers import BounceNotificationHandler 
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler 
from app.messages.auth import OutputAdminUserMessage 


@endpoints.api(name='bounce', version='v1') 
class Bounce(remote.Service): 
    @endpoints.method(message_types.VoidMessage, OutputAdminUserMessage, 
         path="bounce", http_method="POST", 
         name="bounce") 
    def post(self, request): 
     bounce = BounceNotification(request.POST) 
     logging.info('Bounce original: %s', bounce.original) 
     logging.info('Bounce notification: %s', bounce.notification) 

而這似乎並沒有工作,這個API是不是我打嘗試發送電子郵件到[email protected]。任何幫助真的很感激。

回答

1

回答我自己的問題

您不能使用谷歌appengine端點進行設置。我用webapp2來設置這個。

handle_bounced_email.py

import logging 
import webapp2 
from google.appengine.api import mail 
from google.appengine.ext.webapp.mail_handlers import BounceNotification 
from google.appengine.ext.webapp.mail_handlers import BounceNotificationHandler 

class LogBounceHandler(BounceNotificationHandler): 
    def receive(self, bounce_message): 
     mail.send_mail(to='[email protected]', sender='[email protected]', subject='Bounced email', 
         body=str(self.request)) 
     logging.info('Received bounce post ... [%s]', self.request) 
     logging.info('Bounce original: %s', bounce_message.original) 
     logging.info('Bounce notification: %s', bounce_message.notification) 

class BounceHandler(webapp2.RequestHandler): 
    def post(self): 
     bounce = BounceNotification(self.request.POST) 
     logging.info('Bounce original: %s', bounce.original) 
     logging.info('Bounce notification: %s', bounce.notification) 

app = webapp2.WSGIApplication([ 
    ('/_ah/bounce', LogBounceHandler), 
], debug=True) 

現在在app.yaml中添加這些

inbound_services: 
- mail_bounce 

- url: /_ah/bounce 
    script: handle_bounced_email.app 
    login: admin 

login:admin只允許管理員用戶使用這個網址

相關問題