user550738
user550738

Reputation:

python script send emails, how to catch and show error sending email?

I have a pretty simple python script that sends emails, something like this:

import smtplib

from email.MIMEText import MIMEText

msg = MIMEText("test email")
msg['Subject'] = // ... yada yada 

for iIndex in range(0,200):
  s = smtplib.SMTP('smptserver')
  // send the email
  s.quit()

My problem is, typically 1 of the 200 emails will never arrive. I don't see any error messages on the console, so I'm assuming that the email was send to the SMTP server, and the SMTP server is dropping the ball.

But before I bug the SMTP guys, I want to make sure I'm not missing an error somewhere.

Is there somewhere other than the console where python will output the error message?

Thanks, Rob

Upvotes: 2

Views: 320

Answers (1)

Nolen Royalty
Nolen Royalty

Reputation: 18633

If an error was thrown, you'd see something in the console. However, you could probably solve this using SMTP.set_debuglevel() with any true value. Doing this will display "debug messages for connection and for all messages sent to and received from the server."

Upvotes: 3

Related Questions