简体   繁体   English

使用sendmail发送电子邮件不适用于大型电子邮件

[英]Sending emails with sendmail doesn't work for large emails

I'm using python's sendmail in the following way: 我通过以下方式使用python的sendmail

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

This usually works fine (Ie I get the email) but it fails (Ie no exception is shown but the email just doesn't arrive) when the message is pretty big (around 200 lines). 当消息很大(大约200行)时,这通常可以正常工作(即,我收到电子邮件),但会失败(即,不显示异常,但电子邮件没有到达)。 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. 如果将某些电子邮件服务器(例如Yahoo和Hotmail)归类为潜在垃圾邮件,则应在一段时间内考虑将其隔离。 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. 垃圾邮件将取决于内容,图像与文本的比率,附件的性质,html链接的性质,发送速率,重复次数,发件人以及许多其他因素。

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) . 您可以尝试通过以下方式查看SMTP实际发送的内容:将网钩挂在端口上,然后发送到该端口: nc -l 5678然后在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. 如果看起来正确(并且没有理由不这样做),则可以尝试将其提供给telnet localhost smtp以直接查看响应。 That should give you some idea what goes wrong. 那应该让您知道出了什么问题。

I have just started picking around with sending emails through SMPT servers as well. 我也刚刚开始通过SMPT服务器发送电子邮件。 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. 检查您的服务器设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM