在Python中像PHP一样发送邮件
我注意到,PHP 里有一个很简单的函数可以用来发送邮件,我在想在 Python 里能不能做到这一点。我知道 Python 有一个邮件模块,但我了解到使用这个模块需要运行一个 SMTP 服务器,而 PHP 可以直接用 sendmail。
我更希望使用 Python 3,如果能得到一些帮助,我会非常感激。
1 个回答
6
这是一个关于如何在Python中发送邮件的完整教程。看起来他们也有一个叫sendmail的功能,可以去看看。
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"