import os
import smtplib
from email.message import EmailMessage
EMAIL_ID = os.environ.get('USER_ID') #Use the Email Id as an environment variable
EMAIL_PASSWORD = os.environ.get('USER_PASS') #Use the Email password as an environment variable
mails = ['receiver1@gmail.com','receiver2@gmail.com','receiver3@gmail.com']
msg = EmailMessage()
msg['Subject'] = 'Please check the PDF attached'
msg['From'] = EMAIL_ID
msg['To'] = ','.join(mails)
msg.set_content('Check the PDF shared,')
pdf = ['1.pdf'] #Use same directory in which .py is saved, or give the full path of PDF
for file in pdf:
with open(file,'rb') as x:
data = x.read()
file_name = x.name
msg.add_attachment(data,maintype='application',subtype='octet-stream',filename= file_name)
with smtplib.SMTP_SSL('smtp.gmail.com',465) as smtp:
smtp.login(EMAIL_ID,EMAIL_PASSWORD)
smtp.send_message(msg)