像PHP一样用Python发送电子邮件

Tom*_*ese 8 python email sendmail

我注意到php只有一个快速函数来发送电子邮件,我想知道我是否可以用Python做到这一点.我知道Python有一个电子邮件模块,但我知道我需要运行一个SMTP服务器来使用它,而PHP可以使用sendmail.

我最好使用Python 3,对此的任何帮助都将非常感激.

Ben*_*jia 9

这是一个在python中发送电子邮件的完整教程.看起来他们也有sendmail功能.看看

try:
   smtpObj = smtplib.SMTP('localhost')
   smtpObj.sendmail(sender, receivers, message)         
   print "Successfully sent email"
except SMTPException:
   print "Error: unable to send email"
Run Code Online (Sandbox Code Playgroud)