私は Python を使用して、本を送ったが返事がない見込み客をフォローアップする方法を生成します。彼らに追いつくための簡単な方法。これはスパムには使用されないことを強調する必要があります。
GMAIL_USERNAME = "myemail@gmail.com" GMAIL_PASSWORD = "myGmailPassword" を含む gmail_variable.py ファイルが 1 つあります。
以下は、これらの詳細を使用して Google ドライブにログインし、まだ返信がない人にメールを送信します。今日まで絶対に元気に働いています。次のエラーを受け取り始めました。これを端末から実行し、コードを自分のマシンにローカルに保存します。
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
以下は、実行されるコードです。私が読んだものによると、4月20日にoAuthが変更されたことを知っています。しかし、それまでは以下のコードが機能していました。
いくつかの初期調査の後、gspread が置き換えを推奨していることを発見しました
gc = gspread.login(GMAIL_USERNAME, GMAIL_PASSWORD)
と
gc = gspread.authorize(OAuth2Credentials)
次に、こちらのガイドを読み、提案どおりに API をセットアップしました。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 = "nat@programmingformarketers.com"
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]