【发布时间】:2016-08-11 12:31:31
【问题描述】:
在使用 Python 的 smtplib 时如何避免违反 Gmail 的使用条款?
我想使用 Python 发送内部电子邮件。在与 Gmail API 斗争了 2 天后,我放弃了。然后我找到了smtplib 模块,看起来很简单,很有前途。
按照here的例子,我写了一小段Python代码:
import smtplib
# Details of where to send FROM
emailUser = 'an.account.I.made.just.for this.test@gmail.com'
emailPassword = 'password123'
# Send the following message to an address...
message = '[ I am email content ]'
toAddress = 'test.victim@gmail.com'
# Define the HEADER (to, from, and subject)
header = """
To: %s
From: %s
Subject: Python SMTPLIB Test
"""
header = header % (toAddress, emailUser)
# [ Don't know what this does ]
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
# Use User/Password credentials to send email
smtpserver.login(emailUser, emailPassword)
smtpserver.sendmail(emailUser, toAddress, message)
smtpserver.close()
我执行了这个脚本。看起来谷歌的算法一定是把这个解释为恶意发送,并立即关闭了我的账户!这很公平,因为我确信smtplib 很容易被滥用。但是,我有诚实的意图,但我不知道如何解决这个问题:在使用 Python 的smtplib 时如何避免违反 Gmail 的使用条款?
【问题讨论】:
标签: python email gmail policy smtplib