-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.py
31 lines (26 loc) · 1.03 KB
/
mail.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
import smtplib
from email.message import EmailMessage
import imghdr
import codecs
import os
def enviarMail(mail):
print("Starting to send the email.")
newMessage = EmailMessage()
newMessage['Subject'] = "Your QR has arrived!"
newMessage['From'] = '[email protected]'
newMessage['To'] = mail
newMessage.set_content('Let me know what you think. Image attached!')
with open('imagen.png', '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)
#msg_full = message.as_string()
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login('[email protected]', 'yourPassword')
server.sendmail('[email protected]',
mail,
newMessage.as_string())
os.remove("imagen.png")
print("Finished sending email")