-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemails git.py
37 lines (33 loc) · 1.46 KB
/
emails git.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import smtplib
import os
import pandas as pd
from email.message import EmailMessage
# specify the folder where the files are located
folder_path = "folder path" # write here the path of the folder
#Hoja1 is where the emails are located
data = pd.read_excel('file path', sheet_name='Hoja1') # Choose the file and the excel sheet you store the emails of your distribution list
#Hoja2 is the name of the pptx files
data1 = pd.read_excel('file path', sheet_name='Hoja2') # Same file but with the other sheet with the names of the files
#translating into lists
emails = data.values.tolist()
pptx_file = data1.values.tolist()
email_id = "youremail@gmail.com"
email_pass = "yourpassword"
count = 1
for i in range(len(emails)):
receiver = emails[i][0]
msg = EmailMessage()
msg['Subject'] = 'Resultados pruebas psicológicas - Informe'
msg['From'] = email_id
msg['To'] = receiver
msg.set_content('Estimado/a, \nEl presente correo es para ... \nAtentamente, \nEquipo de Investigación')
file = os.path.join(folder_path, pptx_file[i][0])
with open(file,'rb') as f:
file_data = f.read()
file_name = f.name
msg.add_attachment(file_data, maintype='application', subtype = 'vnd.openxmlformats-officedocument.presentationml.presentation', filename=file_name)
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(email_id, email_pass)
smtp.send_message(msg)
print(count)
count = count+1