除 localhost 之外的 Python SMTP

标签 python email smtp

# Import smtplib for the actual sending function
import smtplib

# Import the email modules we'll need
from email.mime.text import MIMEText

# Open a plain text file for reading.  For this example, assume that
# the text file contains only ASCII characters.
fp = open(textfile, 'rb')
# Create a text/plain message
msg = MIMEText(fp.read())
fp.close()

# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'The contents of %s' % textfile
msg['From'] = me
msg['To'] = you

# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP('localhost')
s.sendmail(me, [you], msg.as_string())
s.quit()

s = smtplib.SMTP('localhost')中,我是否必须设置一些东西才能工作..比如stmp服务器?

如果是的话我该怎么做?有人知道我是否可以使用 localhost 以外的 smtp 服务器吗? gmail smtp 服务器对我不起作用,因为它必须通过 gmail api 并且无法将电子邮件作为任意电子邮件发送

[编辑]

s = smtplib.SMTP('mail') 对我有用
有人知道stmp服务器'mail'指的是什么吗?

最佳答案

回答您问题的核心:您确实需要一个 SMTP 服务器。您可以在本地设置,也可以使用远程服务器。

使用哪种 SMTP 服务以及如何设置服务器对于这个社区来说是一个太宽泛的问题 -- 您必须做一些研究然后来返回更具体的问题。

关于除 localhost 之外的 Python SMTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35495411/

相关文章:

Python——如何从随机点开始遍历范围

python - 如何使用 python 正则表达式提取内容可变的数据?

python - 如何使用 Plone 4.1 触发事件提醒邮件

email - 我应该用什么 : bulk e-mails (with MailChimp) or transactional e-mails(with Mandrill)?

c# - 无法向电子邮件发送消息

CentOS iptables 和使用外部 SMTP 服务器的端口配置

python - 使用 OpenCV 从扫描的纸张中提取精确区域?

android - Android 上的 Gmail/iOS 上的默认邮件应用缩小文本

email - 将 Google Plus(一个或共享)链接添加到电子邮件简报

c# - SMTP Gmail 超时