我使用python生成一种跟踪已发送书籍但未收到回复的潜在客户的方法。快速的方式赶上他们。必须强调这不是用于垃圾邮件。无法使用gspread进行身份验证以访问Google Drive
我有一个包含GMAIL_USERNAME =“[email protected]” GMAIL_PASSWORD =“myGmailPassword”
下使用这些信息登录到谷歌驱动器和电子邮件的人谁没有拿到一个文件gmail_variable.py回到我的身边。直到今天工作都很好。开始收到以下错误。我从终端运行此代码,并将代码保存在本地机器上。
Traceback (most recent call last):
File "pr_email_robot.py", line 6, in <module>
gc = gspread.login(GMAIL_USERNAME, GMAIL_PASSWORD)
File "/Library/Python/2.7/site-packages/gspread/client.py", line 312, in login
client.login()
File "/Library/Python/2.7/site-packages/gspread/client.py", line 119, in login
"Unable to authenticate. %s code" % ex.code)
gspread.exceptions.AuthenticationError: Unable to authenticate. 404 code
下面是执行的代码。根据我阅读的内容,我知道oAuth是4月20日的变化。但是直到那时,下面的代码才开始工作。
一些初步的研究后,我发现,gspread建议与
gc = gspread.authorize(OAuth2Credentials)
我然后通过引导here和设置的API去为他们建议更换
gc = gspread.login(GMAIL_USERNAME, GMAIL_PASSWORD)
。下载了JSON文件。但是,我将OAuth2Credentials替换为什么?
gc = gspread.authorize(OAuth2Credentials)
任何想法或建议非常感谢。还是很新的Python这样简单的解释是有帮助:)
import smtplib
import gspread
from gmail_variables import *
gc = gspread.login(GMAIL_USERNAME, GMAIL_PASSWORD)
wks = gc.open("horror_reviewers").sheet1
recipients = wks.get_all_values()
def sendEmail(recipient):
email_subject = "Jay-Jay"
#recipient = "[email protected]"
body_of_email = "<body><p>Hello "+ recipient[1].encode('utf-8') +",<br /> \
<br /> \
We spoke in the last few months X book.<br /> \
<br /> \
Have a note that we sent you a copy and confirmed a review. Did we send over what you needed or are you still awaiting details from us?</a><br /> \
<br /> \
Apologies if you have already posted the link and we missed it. If you could resend that would be great.<br /> \
<br /> \
</p></body>"
session = smtplib.SMTP('smtp.gmail.com', 587)
session.ehlo()
session.starttls()
session.login(GMAIL_USERNAME, GMAIL_PASSWORD)
headers = "\r\n".join(["from: " + GMAIL_USERNAME,
"subject: " + email_subject,
"to: " + recipient[0],
"mime-version: 1.0",
"content-type: text/html"])
# body_of_email can be plaintext or html!
content = headers + "\r\n\r\n" + body_of_email
session.sendmail(GMAIL_USERNAME, recipient[0], content)
[sendEmail(i) for i in recipients]
感谢@VikashSingh,但它没有像现有系统一样与Google Drive集成。 – PatGW
检查如何使用gspread,将包括在代码.. –
你可以尝试这个链接,看看它是否适用于你:http://gspread.readthedocs.org/en/latest/oauth2.html –