0

My app engine fails to receive emails for some sender and bounces back with the following message:

*********************************************************************************
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 ----------
*********************************************************************************

From above text, I am not able to find the error cause.

Note: It works fine for many of the senders. I have NOT enabled login: admin for mail service.

Here is my code snippet:

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

Handler in 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)

Any suggestions to find the reason of bounce back?

Drew Gaynor
  • 8,292
  • 5
  • 40
  • 53
sheenu85
  • 168
  • 2
  • 11
  • Could it be that an exception occurs in your incoming mail handler? (Python: https://developers.google.com/appengine/docs/python/mail/receivingmail Java: https://developers.google.com/appengine/docs/java/mail/receiving) Looks to me as if the mail is properly received by google but something happens afterwards, so it's probably in your code. – konqi Sep 04 '12 at 09:49
  • It works fine for many of the senders. If there is any issue in incoming mail handler, it should be there in app engine error logs too. seems mail is not being received at all. – sheenu85 Sep 04 '12 at 09:56
  • well you're not giving us much here... there is no problem visible in the mail header. You can easily analyze mail headers at https://toolbox.googleapps.com/apps/messageheader/ by the way. You may want to post some code of your mail handler. – konqi Sep 04 '12 at 10:04
  • updated the code, please check, let me know if I need to put more info. – sheenu85 Sep 04 '12 at 10:25
  • try wrapping all in receive in try-except-construct and log something or send something... You should at least get an error there. Not really a python guy, sorry. – konqi Sep 04 '12 at 13:41
  • You would see a log entry in app engine if the e-mail was hitting your code and failing (unless you have one giant try/except that would suppress an exception stack trace). Even if your code did fail to process the email, you would not get a bounce back to the sender. Was there no additional information provided by the MTA in the rejection e-mail other than what you provided? It may be the e-mail service you are using to send e-mails out via. – someone1 Sep 04 '12 at 21:34
  • @JoSo, I put it in try and caught the cause. error was processing attachment(csv). It still shouldn't have given mail delivery failure as mail still reaches to destination. Anyways, got it resolved. Thanks, and thanks for providing tool to analyze mail headers. cheers. – sheenu85 Sep 05 '12 at 10:18
  • You are most welcome. I'm glad you found the error using the try-catch i suggested. If you found a solution it would be great if you post it here as an answer for others if they should have the same problem. – konqi Sep 05 '12 at 11:07

1 Answers1

0

put the code in try-catch and got error in processing attachment: 'new-line character seen in unquoted field - do you need to open the file in universal-newline mode?' It got resolved using content.decode().splitlines().

Though it shouldn't have given mail delivery failure as mail still reaches to destination. Thanks JoSo.

sheenu85
  • 168
  • 2
  • 11
  • If your script returns an error status, this is taken as an indication that the message didn't successfully reach its destination. Essentially, your script is the mail server, not the traditional mail server that POSTs the message to that script. – Wooble Sep 06 '12 at 10:31