在应用引擎上接收邮件 - 电子邮件会为某些发件人退回

时间:2012-09-04 09:40:46

标签: python google-app-engine email email-bounces

我的应用引擎无法接收某些发件人的电子邮件,并使用以下消息退回:

*********************************************************************************
Delivery to the following recipient failed permanently:

     sometext@my-app-id.appspotmail.com

----- Original message -----

Received: by <recipient's ip> with SMTP id o5mr5102778igd.2.1346674874496;
        Mon, 03 Sep 2012 05:21:14 -0700 (PDT)
Return-Path: <sender-email@senderdomain.com>
Received: from mail-ie0-f177.senderdomain.com (mail-ie0-f177.senderdomain.com [<sender-ip>])
        by gmr-mx.senderdomain.com with ESMTPS id wo9si719480igc.1.2012.09.03.05.21.14
        (version=TLSv1/SSLv3 cipher=OTHER);
        Mon, 03 Sep 2012 05:21:14 -0700 (PDT)
Received-SPF: pass (senderdomain.com: domain of sender-email@senderdomain.com designates <sender-ip> as permitted sender) client-ip=<sender-ip>;
Authentication-Results: gmr-mx.senderdomain.com; spf=pass (senderdomain.com: domain of sender-email@senderdomain.com designates <sender-ip> as permitted sender) smtp.mail=sender-email@senderdomain.com; dkim=pass header.i=@senderdomain.com
Received: by ieje10 with SMTP id e10so4602552iej.22
        for <sometext@my-app-id.appspotmail.com>; Mon, 03 Sep 2012 05:21:14 -0700 (PDT)

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=senderdomain.com; s=20120113;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :content-type:x-system-of-record;
        bh=XiHGSzr6o8p0wD7eNTHFG0qcWyXJz75LsjP/5TXbwYc=;
        b=mL9J2xP7mLM5VVKGgc9dhBCV7RClZOtIqyhE22JQlNro8jiCB/nBZBmzmv2G3wsoMw
         I3lRTKUmJFXKI07IFEHKAISQn/QuIQloR6Cn5H8eAMQBlXUbmmvC2Uq6g7mjiD3KV4Hf
         4RgHfe2B2cNrGNPLNMQF/Ftcn5cmb/NfikgefjvcVoxrf5/Y15JgR609/k5fyLVYSjxb
         uYFW9fNiPl9Cf0r/Blm5aEWkrNACyF86tbSTpH48XrxXIRU/riUgjbKIfrX4EArbUmuk
         sqEAxDYwHPrzLhyV/r8q1dPuJzISGQ2xJ9tYtZnrN4ExtKkvgqGg4Yh9QS1nFpcWVfrP
         Uniw==

X-<sender-domain>-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=senderdomain.com; s=20120113;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :content-type:x-system-of-record:x-gm-message-state;
        bh=XiHGSzr6o8p0wD7eNTHFG0qcWyXJz75LsjP/5TXbwYc=;
        b=oMfU8AGDLjA77FgK3imDh6sQdT+Fl37x/3P7ZOh8Ac7oTB4HEkfWClpAU3Ui7y3d9T
         BnsKRTCx7H/xUSYdguCU5eRyUmuo4wwTIgAi/OT7Do1nTecJx5DB8u416bflfkonBeSD
         RTyjjfan1NIG/fC8yF26DCMSFKJnKQNbCHlxB+LlYWMBrl5HO1Fxc+nYHf9qtha8qedT
         5B3TUFrLm1QS5FfIPJGq8jtTONANWa1vBijMAJReU6qauuKoPsVgTgWZ9B+grgE0Nfn3
         w6rUCxzq90d4R+QWcMzWDfzYksIhBgv/6NECjbSFiX0fVw/3vM1z9mCNbUNkB9rbyE0I
         DVkg==
Received: by 10.50.181.136 with SMTP id dw8mr10648907igc.31.1346674874247;
        Mon, 03 Sep 2012 05:21:14 -0700 (PDT)
Received: by 10.50.181.136 with SMTP id dw8mr10648883igc.31.1346674873921;
 Mon, 03 Sep 2012 05:21:13 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.50.214.39 with HTTP; Mon, 3 Sep 2012 05:20:53 -0700 (PDT)
In-Reply-To: <20120829165751.F24167488531@new_msg2.rancardsolutions.com>
References: <20120829165751.F24167488531@new_msg2.rancardsolutions.com>
From: <Sender-name> <sender-email@senderdomain.com>
Date: Mon, 3 Sep 2012 13:20:53 +0100
Message-ID: <CAOS-8ONnuWfPRhDuKseTOhjG94pBMVKq8PDQJw_gPuWdmEySUA@mail.gmail.com>

Subject: Fwd: GMAIL-SMS Summary(Active Networks)
To: sometext@my-app-id.appspotmail.com
Content-Type: multipart/mixed; boundary=14dae93408a37cf2e404c8cb2d38
X-System-Of-Record: true
X-Gm-Message-State: ALoCoQmNK+HxrLzS52zrj9RKLG9C/MeBJ5NiXcp9/+zVSFRGJtWvI0xGeO2x/e1bOR/sFUDQNYJjNj3KJfmI5L58JnRqz5WCe8/qCEjIDWNInsL1v9qew06Z7OEesEKEBgJazox1pAuQE8+J9syvYJdNXmGMaFHNvZcyEd8WkAdY1Pdbk8pNu1WyVK3ogioHs1kmpR5OQfvYHfBUArF95Z+fmVQldDSfgA==

---------- Forwarded message ----------
*********************************************************************************

从上面的文字,我无法找到错误原因。

注意:它适用于许多发件人。 我没有启用login:admin for mail service。

这是我的代码段:

的app.yaml

--------

application: my-app
version: 2
runtime: python
api_version: 1

handlers:
- url: /remote_api
  script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
  login: admin

- url: /_ah/mail/sometext@my-app.appspotmail.com
  script: process_email.py

- url: .*
  script: main.py

inbound_services:
- mail

process_email.py中的处理程序

  def receive(self, mail_message):
    if not hasattr(mail_message, 'attachments'):
      err = 'No attachment found.'
      self.status = 'ERROR'
      self.status_message.append(err)
      self.SendStatusMail(mail_message.sender)
      return
    for name, content in mail_message.attachments:
      report_time_period = self.GetReportTimePeriod(name)
      report_date = self.GetReportDate(name)
      if report_time_period and report_date and name.endswith('.csv'):
        records, product_prefix = self.ProcessCsv(content)
        if records and product_prefix:
          self.UpdateRecordsToDb(report_time_period, report_date, records,
                                 product_prefix)
      else:
        err = ('Invalid file name %s.' % (name))
        self.status = 'ERROR'
        self.status_message.append(err)


  self.SendStatusMail(mail_message.sender)

有任何建议可以找到反弹的原因吗?

1 个答案:

答案 0 :(得分:0)

将代码放在try-catch中并在处理附件时遇到错误: '在不带引号的字段中看到的新行字符 - 您是否需要以通用换行模式打开文件?'它已使用content.decode()。splitlines()解析。

虽然邮件仍然到达目的地,但它不应该给邮件传递失败。 谢谢JoSo。