Sending emails with sendmail doesn't work for large emails
I'm using python's sendmail
in the following way:
msg = <开发者_如何学JAVASOME 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?
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.
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('you@example.com','me@example.com','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.')
{}
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.
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.
精彩评论