<p>有关使用outlook的解决方案,请参见下面的理论答案。</p>
<p>否则,请使用python附带的smtplib。请注意,这将要求您的电子邮件帐户允许smtp,这在默认情况下不一定启用。</p>
<pre><code>SERVER = "smtp.example.com"
FROM = "yourEmail@example.com"
TO = ["listOfEmails"] # must be a list
SUBJECT = "Subject"
TEXT = "Your Text"
# Prepare actual message
message = """From: %s\r\nTo: %s\r\nSubject: %s\r\n\
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
# Send the mail
import smtplib
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()
</code></pre>
<p><strong>编辑:</strong>此示例使用如<a href="https://tools.ietf.org/html/rfc2606" rel="nofollow noreferrer">RFC2606</a>中所述的保留域</p>
<pre><code>SERVER = "smtp.example.com"
FROM = "johnDoe@example.com"
TO = ["JaneDoe@example.com"] # must be a list
SUBJECT = "Hello!"
TEXT = "This is a test of emailing through smtp of example.com."
# Prepare actual message
message = """From: %s\r\nTo: %s\r\nSubject: %s\r\n\
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
# Send the mail
import smtplib
server = smtplib.SMTP(SERVER)
server.login("MrDoe", "PASSWORD")
server.sendmail(FROM, TO, message)
server.quit()
</code></pre>
<p><sub>要让它真正与gmail一起工作,Doe先生需要转到gmail中的“选项”选项卡并将其设置为允许smtp连接。</sub></p>
<p>注意添加了登录行以对远程服务器进行身份验证。最初的版本不包括这个,这是我的疏忽。</p>