views:

84

answers:

4

I'm using python's sendmail in the following way:

msg = <SOME MESSAGE>
s = smtplib.SMTP('localhost')
s.sendmail(me, you, msg.as_string())
s.quit()

This usually works fine (I.e I get the email) but it fails (I.e no exception is shown but the email just doesn't arrive) when the message is pretty big (around 200 lines). Any ideas what can cause this?

A: 

You can try seeing what SMTP actually sends by hooking a netcat on a port then sending there: nc -l 5678 then in Python smtplib.SMTP('localhost', 5678).

If that looks correct (and there should be no reason why it wouldn't), you can try giving it to telnet localhost smtp to see the response directly. That should give you some idea what goes wrong.

Amadan
+2  A: 

Who are you sending to? You should consider some email servers (such as Yahoo and Hotmail) quarantine incoming email for a period of time if the email is categorized as potential spam. Spamminess is going to be a function of the content, image to text ratio, nature of attachments, nature of html links, sending rate, number of duplicates, sender, and numerous other factors.

vin
you were right. the email was quarantined by our mail service
Guy
+1  A: 

Try setting the debuglevel to get a trace of the protocol progress.

SMTP.set_debuglevel(level)

Set the debug output level. A true value for level results in debug messages for connection and for all messages sent to and received from the server.

When a message is successfully queued, the tail of the debug trace looks like:

>>> conn = smtplib.SMTP('mail')
>>> conn.set_debuglevel(1)
>>> conn.sendmail('[email protected]','[email protected]','subject: test\n\ntest.\n')
...
send: 'subject: test\r\n\r\ntest.\r\n.\r\n'
reply: '250 2.5.0 Message received and queued.\r\n'
reply: retcode (250); Msg: 2.5.0 Message received and queued.
data: (250, '2.5.0 Message received and queued.')
{}
gimel
I did that, the debug message is very similar to what you posted: it says `reply: retcode (250); Msg: 2.0.0 o5HBqnuj018702 Message accepted for delivery`. What now? Do you think it's quarantined?
Guy
Mail is queued - next step is to check inside the SMTP server logs. The python script is functioning OK.
gimel
A: 

I have just started picking around with sending emails through SMPT servers as well. What software are you using to create your localhost server? sometimes the software may be setup to reject messages over a given length. Check your server settings.

Richard