forked from CodeIt-Bro/Python-Email-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiImageAttach.py
27 lines (21 loc) · 979 Bytes
/
MultiImageAttach.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
import smtplib
import imghdr
from email.message import EmailMessage
Sender_Email = "[email protected]"
Reciever_Email = "[email protected]"
Password = input('Enter your email account password: ')
newMessage = EmailMessage()
newMessage['Subject'] = "Check out the new logo"
newMessage['From'] = Sender_Email
newMessage['To'] = Reciever_Email
newMessage.set_content('Let me know what you think. Image attached!')
files = ['codeitbro-logo.png', 'cat.gif']
for file in files:
with open(file, 'rb') as f:
image_data = f.read()
image_type = imghdr.what(f.name)
image_name = f.name
newMessage.add_attachment(image_data, maintype='image', subtype=image_type, filename=image_name)
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(Sender_Email, Password)
smtp.send_message(newMessage)