WebFaction
Community site: login faq

I'm forwarding mail with a python script with an excerpt below. It receives mail through a python script, and forwards it to another address, but if it has a large attachment though, it sends an email back to my original address saying their was an error. Is there a way to "catch" the error? Even though it's within the try/except loop, it doesn't "catch" it. I don't actually need to forward the large attachments, but I do need the script to be able to notify me if the attachment was too large. Is it possible to catch the error? Or do I need to actually check the attachment size?


== email error message ==

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to <postmaster>

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

                  The mail system

<script-xxxxx@mx8.webfaction.com>: Command
   died with status 1: "/home/ph/trunk/scripts/utility/mail2script.py
   pittmedstech@WebXXX:/home/myusername/myscript.py". Command output:
   Traceback (most recent call last):   File
   "/home/ph/trunk/scripts/utility/mail2script.py", line 50, in ?     raise
   "Error" Error

== excerpt from myscript.py ===

s = SMTP()
s.connect('smtp.webfaction.com')
s.login('my_mailbox_name','password1')

try:
        s.sendmail(mailfrom,  [mailto], message_as_string )

except smtplib.SMTPException:
    LOGGER.warn('SMTP exception',  exc_info=1);
    error_message = sys.exc_info()[0]
except:
    LOGGER.warn('Exception',  exc_info=1);
    error_message=sys.exc_info()[0]
finally:
    s.quit()
# Check error_message and do other stuff

asked 03 Oct '11, 19:59

scornflakes
113
accept rate: 0%

edited 03 Oct '11, 20:03


The error itself is happening on WebFaction's side, when we send your mail through our mail2script implementation. Since it's happening there, and not in your own script, you can't catch it.

As a workaround, you can use this mail2script replacement - it won't solve the problem of not being able to catch an error on the receiving end in the script that sends the message, but it won't throw an error when it receives a message with a large attachment, so perhaps if you use that you won't have an error to catch.

Hope that helps!

permanent link

answered 03 Oct '11, 22:12

seanf
12.2k41836
accept rate: 37%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×260
×2

question asked: 03 Oct '11, 19:59

question was seen: 2,348 times

last updated: 03 Oct '11, 22:12

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM