用python接收和发送电子邮件
发布于 2021-01-29 16:18:15
如何使用python接收和发送电子邮件?一种“邮件服务器”。
我正在考虑制作一个应用程序,以侦听它是否接收到发送到foo@bar.domain.com的电子邮件,并将电子邮件发送给发件人。
现在,我能够在python中完成所有操作,最好使用3rd party库吗?
关注者
0
被浏览
143
1 个回答
-
这是一个非常简单的示例:
import smtplib server = 'mail.server.com' user = '' password = '' recipients = ['user@mail.com', 'other@mail.com'] sender = 'you@mail.com' message = 'Hello World' session = smtplib.SMTP(server) # if your SMTP server doesn't need authentications, # you don't need the following line: session.login(user, password) session.sendmail(sender, recipients, message)
有关更多选项,错误处理等,请参阅smtplib模块文档。