Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29745

How do I attach separate PDF's to contact list email addresses using Python?

$
0
0

I have written a script that sends individual emails to all contacts in an Excel table. The table looks like this:

Names Emails             PDF
Name1 Email1@email.com   PDF1.pdf 
Name2 Email2@email.com   PDF2.pdf

The code I have so far is as follows:

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
from string import Template

import pandas as pd

e = pd.read_excel("Contacts.xlsx")

emails = e['Email'].values
PDF = e['PDF'].values
print(emails, PDF)

server = smtplib.SMTP(host='smtp.outlook.com', port=587) 
server.starttls()
server.login('sender_email','sender_password')

msg = ("""
Hi there

Test message

Thankyou
""")

subject = "Send emails with attachment"

body = "Subject: {}\n\n{}".format(subject,msg)   
for emails in emails:
    server.sendmail('sender_email',emails,body)

print("Emails sent successfully")

server.quit()

Question: How can I look up the correct attachment (column 3) for each e-mail address (column 2) and attach it to the email using Python?


Viewing all articles
Browse latest Browse all 29745

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>