通过 Python 发送电子邮件
我正在尝试使用 Python 发送电子邮件。据我所知,以下代码需要的只是一个有效的收件人和一个主机HOST。我不确定如何获得主机。最简单的方法是什么?
import smtplib
import string
SUBJECT = "Test email from Python"
TO = "[email protected]"
FROM = "[email protected]"
text = "blah blah blah"
BODY = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % SUBJECT ,
"",
text
), "\r\n")
server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO], BODY)
server.quit()
I'm attempting to send an email with Python. From what I can tell, all the following code needs is a valid recipient and a host HOST. I'm unsure on how to get the host. What is the simplest way?
import smtplib
import string
SUBJECT = "Test email from Python"
TO = "[email protected]"
FROM = "[email protected]"
text = "blah blah blah"
BODY = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % SUBJECT ,
"",
text
), "\r\n")
server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO], BODY)
server.quit()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HOST 是您的 ISP 提供的 SMTP 中继(通常与您的发件人地址的域名相关)。如果您使用桌面邮件客户端,您将能够看到邮件设置中列出的 SMTP 服务器。如果您使用共享主机进行托管,您的主机提供商应该能够提供 SMTP 服务器供您使用。
The HOST is the SMTP relay provided by your ISP (typically related to the domain name of your from address). If you use a desktop mail client, you'll be able to see the SMTP server listed in your mail settings. If you're hosting using shared hosting, your hosting provider should be able to provide an SMTP server for you to use.