在Ubuntu上使用Python通过localhost发送电子邮件

时间:2012-06-10 17:39:49

标签: python ubuntu smtp

我有以下简单的代码来发送电子邮件:

server = smtplib.SMTP('localhost')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

然而,邮件永远不会被发送。我添加了“set_debuglevel”行以尝试进行故障排除,但输出对我来说并不重要:

send: 'ehlo [127.0.1.1]\r\n'
reply: '250-ubuntu\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-SIZE 10240000\r\n'
reply: '250-VRFY\r\n'
reply: '250-ETRN\r\n'
reply: '250-STARTTLS\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250-8BITMIME\r\n'
reply: '250 DSN\r\n'
reply: retcode (250); Msg: ubuntu
PIPELINING
SIZE 10240000
VRFY
ETRN
STARTTLS
ENHANCEDSTATUSCODES
8BITMIME
DSN
send: 'mail FROM:<info@foobarconsulting.com> size=337\r\n'
reply: '250 2.1.0 Ok\r\n'
reply: retcode (250); Msg: 2.1.0 Ok
send: 'rcpt TO:<adam@foobarconsulting.com>\r\n'
reply: '250 2.1.5 Ok\r\n'
reply: retcode (250); Msg: 2.1.5 Ok
send: 'data\r\n'
reply: '354 End data with <CR><LF>.<CR><LF>\r\n'
reply: retcode (354); Msg: End data with <CR><LF>.<CR><LF>
data: (354, 'End data with <CR><LF>.<CR><LF>')
send: 'Hello!\r\n\r\nThe below URLs are either broken or taking too long to respond:\r\nhttp://www.google.com/does-not-exist/\r\nhttp://www.cnn.com/does-not-exist\r\n\r\nLog in and navigate to http://blahblah.com/wp-admin to update the content.\r\n\r\nThanks,\r\n\r\nYour friends at Foo Bar Consulting\r\n.\r\n'
reply: '250 2.0.0 Ok: queued as E7B8820144\r\n'
reply: retcode (250); Msg: 2.0.0 Ok: queued as E7B8820144
data: (250, '2.0.0 Ok: queued as E7B8820144')
send: 'quit\r\n'
reply: '221 2.0.0 Bye\r\n'
reply: retcode (221); Msg: 2.0.0 Bye

我已经安装了postfix(我相信它是在我使用标准LAMP软件包设置我的Ubuntu时默认安装的)但是我不知道还能去哪里寻求帮助。

任何见解或想法将不胜感激。

1 个答案:

答案 0 :(得分:0)

  1. 您可能需要查看sendmail的日志

  2. 确保您的本地DNS有效。试试ping foobarconsulting.com