-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
36 lines (27 loc) · 979 Bytes
/
main.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
from decouple import config
import smtplib
from email.message import EmailMessage
import imghdr
EMAIL_ADDRESS = config('GMAIL_ADDRESS')
EMAIL_PASS = config('GMAIL_PASS')
msg = EmailMessage()
msg['Subject'] = 'This is a reminder'
msg['From'] = EMAIL_ADDRESS
msg['To'] = EMAIL_ADDRESS # sending to myself
msg.set_content("Don't forget to order the movie tickets for tonight")
# adding attachments option
files_to_attach = ['bond.jpg']
for file in files_to_attach:
with open(file, 'rb') as f:
attachment_file = f.read()
attachment_name = f.name
attachment_type = imghdr.what(attachment_name)
msg.add_attachment(attachment_file, maintype='image',
subtype=attachment_type,
filename=attachment_name)
def send_email():
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(EMAIL_ADDRESS, EMAIL_PASS)
smtp.send_message(msg)
if __name__ == "__main__":
send_email()