所以我有一个CSV文件,其中包含大约1000封电子邮件,姓名,公司等。一旦我部署了我的程序,它就会收到大约80封电子邮件,然后我假设Google阻止我再次请求再次访问其服务器。
我想我设置了一个计时器,每70封电子邮件,删除数据框中的每个,等待几分钟,然后从停止的位置开始重新部署,因为已删除的行。你认为这会有用吗?如果是这样,我将如何构建这样的小计时器?我可以创建一个跟踪器,但是如何初始化程序的重新运行?
还有其他潜在的解决方法吗?这是否与我的代码不断辞职进入谷歌有关?
import smtplib
import pandas as pd
class Gmail(object):
def __init__(self, email, password, recepient):
self.email = email
self.password = password
self.recepient = recepient
self.server = 'smtp.gmail.com'
self.port = 465
session = smtplib.SMTP_SSL(self.server, self.port)
session.ehlo
session.login(self.email, self.password)
self.session = session
print('Connected to Gmail account successfully.')
def send_message(self, subject, body):
headers = [
"From: " + self.email,
"Subject: " + subject,
"To: " + self.recepient,
"MIME-Version: 1.0",
"Content-Type: text/html"]
headers = "\r\n".join(headers)
self.session.sendmail(
self.email,
self.recepient,
headers + "\r\n\r\n" + body)
print('- Message has been sent.')
df = pd.read_csv('export.csv', error_bad_lines=False)
for index, row in df.iterrows():
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
comp_name = (row['Account Name'])
print('Email to: ' + comp_name)
per_name = (row['Primary Contact: Full Name'])
print('Email to: ' + per_name)
rec = (row['Primary Contact Email'])
print('Email to: ' + rec)
message_body = 'Hi'
gm = Gmail('email@gmail.com', 'password', rec)
gm.send_message('test', message_body)
print('-- Message for ' + rec + ' (' + comp_name + ') is completed.')
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
print('*********************************')
print('Finish reading through CSV.')
print('*********************************')
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
任何想法都会非常有用。
谢谢!