首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >谷歌应用引擎- python有可能收到电子邮件反弹通知吗?

谷歌应用引擎- python有可能收到电子邮件反弹通知吗?
EN

Stack Overflow用户
提问于 2016-02-24 13:00:05
回答 1查看 301关注 0票数 0

我有一个使用纯python的google端点项目,我使用内置的邮件发送电子邮件。但由于某些原因,电子邮件没有到达接收者(配额还没有用完)。所以我想创建一个弹跳通知器。到目前为止,我已经这样做了。

app.yaml

代码语言:javascript
复制
inbound_services:
- mail_bounce
handlers:
- url: /_ah/bounce
  script: applications.APPLICATION
  login: admin

applications.py

代码语言:javascript
复制
from app.api.bounce.api import Bounce

APPLICATION = endpoints.api_server([Bounce])

bounce.py

代码语言:javascript
复制
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没有被击中。任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-01 04:33:12

回答我自己的问题

您不能使用google应用程序终结点来设置它。我使用webapp2来设置这个。

handle_bounced_email.py

代码语言:javascript
复制
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中添加一个

代码语言:javascript
复制
inbound_services:
- mail_bounce

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

login:admin只允许管理员用户使用此url。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35602915

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档