Я пытаюсь автоматизировать процесс холодных продаж по электронной почте с помощью Python.Я в основном хочу поместить кучу информации в лист Google.Значения столбца в Google Sheet: имя, адрес электронной почты, компания, отслеживание, новость.Follow Ups из следующих значений (пытаясь выяснить способ отслеживания # последующих действий): Да, # 1, # 2, Нет
Я могу читать данные из Google Sheet, и ябыл в состоянии отправить электронное письмо.
Вот Google Sheet `.
Вот мой код:
import csv
import smtplib
import gspread
import pandas as pd
import pprint
from oauth2client.service_account import ServiceAccountCredentials
from emailsettings import USERNAME, PASSWORD
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)
sheets = client.open('Example').sheet1
sh = client.open_by_url('https://docs.google.com/spreadsheets/d/1RkzEkCJ4kEbdsW4-LqyO8bKTKBm9XlXrMp49UxIpotQ/edit#gid=0')
sheet = sh.get_worksheet(0)
data1 = sheet.get_all_values()
smtp = smtplib.SMTP('smtp.gmail.com',port=587,timeout=10)
smtp.starttls()
smtp.login(USERNAME,PASSWORD)
INITIAL_MESSAGE = """
Hi {},
I came across your name while looking for contacts at {}. Huge fan of your work.
I'm a person and I'm the founder and COO of this company. This Company is a full-service internet marketing agency, specializing in social media advertising. We've worked with Fortune 500 Company and many others.
I'm reaching out because we've helped several companies with increasing their ROI and wanted to see if you were open to discussing your digital goals for 2019.
Would you be open to hop on a quick call? Here's my schedule for the week.
Looking forward to hearing from you.
Thanks, Name
PS: Congrats on the {}
"""
FOLLOW_UP = """
Hey {}, how's {}? Hope you're doing awesome.
Reading more about your background, super impressed - by the way, congrats on {}.
I briefed my team about doing social media ads for {} and they're super excited.
Can you meet sometime this week? Otherwise, here's my schedule so pick a time that works well for you.
Cheers,
Name
"""
SECOND_FOLLOW_UP="""
Hey {},
Just wanted to see how things were going at {}. Just wanted to check if you were still interested in chatting sometime about working with Company.
If you're interested, send me over a list of times so we can chat.
Thanks, Name
PS: Congrats on {}
"""
smtp = smtplib.SMTP('smtp.gmail.com',port=587,timeout=10)
smtp.starttls()
smtp.login(USERNAME,PASSWORD)
iterdata = iter(data1)
next(iterdata)
for elem in data1:
name, email, company, follow, news = elem
if follow == 'No':
subject = 'Hey {}, FOLLOW UP #1, {} and Company'.format(name, company, news)
msg = FOLLOW_UP.format(name,company,company, news)
elif follow =='1':
subject = 'Hello, {}, FOLLOW UP #2'.format(company)
msg = INITIAL_MESSAGE.format(name,company, news, company)
elif follow =='2':
subject = 'Hello again, {}, FOLLOW UP #3'.format(company)
msg = SECOND_FOLLOW_UP.format(name,company, news)
else:
print('{}\n'.format(company))
email_msg = 'Subject: {} \n\n {}'.format(subject, msg)
smtp.sendmail(from_addr=USERNAME ,to_addrs=email, msg=email_msg)
print(email_msg)
smtp.quit()
Он выводит" Company "и выдает мне эту ошибку:
NameError: name 'subject' is not defined
Моя цель - заполнить электронную таблицу информацией об электронной почте, человеке, компании и новостях.После заполнения электронной таблицы и запуска сценария он отслеживает количество последующих проверок и генерирует электронное письмо на основе нескольких доступных шаблонов.
Я слышал, что это будет проще, если создать классы, методы и атрибуты., но не совсем уверен, как это сделать.
Заранее спасибо!