Mark Finch
Mark Finch

Reputation: 766

Handling / Bouncing Incoming Email on Errors with App Engine Python

When an email is received that generates an error what is the best way to bounce the message? For example you store a file in a db.BlobProperty but an email comes in that exceeds the 1m limit. There needs to be a bounce error to the request somehow so the email doesn't keep hitting the server and increasing the billing every 15 minutes. (Don't ask me how I know :-P ... not really it is a separate but related issue I posted in another question. here )

But that other error made it clear I need to deal with this before I get that email with multiple attachments that nails me for 1gb of data.

Normally the mail server handles the bounce, like when you send to a bad address and returns an error to the client/server. I have searched and didn't find anything helpful on this. YMMV

Is there an undocumented function? What is the proper response to return so that the originating server stops sending?

Upvotes: 0

Views: 394

Answers (1)

Nick Johnson
Nick Johnson

Reputation: 101149

There's no way to bounce a message once it arrives at your App Engine app. You have two options:

  1. Send the user a 'bounce message' yourself using the outgoing email API
  2. Silently discard the message

In either case, you should install a top-level exception handler (frameworks like webapp and webapp2 have support for this) that logs the exception, performs the appropriate action, and then returns status code 200 instead of 500, so the message won't be redelivered repeatedly.

In your specific case, too, I'd start storing the attachments in the blobstore instead of a blob property, to avoid the 1MB limit.

Upvotes: 2

Related Questions