是否可以接收 google 应用引擎 - python 的电子邮件退回通知?
Is it possible to receive email bounce notifications for google app engine - python?
我有一个使用纯 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)
这似乎不起作用,因为当我尝试向 xyz@gmail.com 发送电子邮件时,API 没有命中。非常感谢任何帮助。
回答我自己的问题
您不能使用 google 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='ajai@qburst.com', sender='ajai@qburst.com', 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
只允许管理员用户使用此 url
我有一个使用纯 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)
这似乎不起作用,因为当我尝试向 xyz@gmail.com 发送电子邮件时,API 没有命中。非常感谢任何帮助。
回答我自己的问题
您不能使用 google 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='ajai@qburst.com', sender='ajai@qburst.com', 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
只允许管理员用户使用此 url