-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmail_Auto_Test.py
More file actions
70 lines (56 loc) · 1.78 KB
/
Copy pathEmail_Auto_Test.py
File metadata and controls
70 lines (56 loc) · 1.78 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Scratch
#!/usr/bin/env python3
import os
import smtplib
import imghdr
from email.message import EmailMessage
Email_Address = os.environ.get('DB_USER')
Email_Password = os.environ.get('DB_PASS')
msg = EmailMessage()
msg['Subject'] = 'INGENIOUS PRINTS'
msg['From'] = Email_Address
msg['To'] = 'm_ashfaque@hotmail.com'
msg.set_content('IMAGE ATTACHED')
#TO ADD HTML TEXT:
#msg.add_alternative("""\
#<!DOCTYPE html>
#<html>
# <body>
# <h1 style="color:SlateGray;">This is an HTML Email!</h1>
# </body>
#</html>
#""", subtype='html')
#TO ATTACH SINGLE FILE:
#with open('D:\PICTURE\LOGO\y.jpg', 'rb') as f:
# file_data = f.read()
# file_type = imghdr.what(f.name)
# file_name = f.name
#TO ATTACH MORE FILES:
files = ['D:\DOCUMENT\CV\CV_2020.pdf']
for file in files:
with open(file, 'rb') as f:
file_data = f.read()
#NOT REQ IF IT'S NOT IMAGE-
# file_type = imghdr.what(f.name)
file_name = f.name
#FOR PDF:
msg.add_attachment(file_data, maintype='application', subtype='octet-stream', filename=file_name)
#FOR MULTI IMAGE:
# msg.add_attachment(file_data, maintype='image', subtype=file_type, filename=file_name)
#FOR SINGLE IMAGE:
#msg.add_attachment(file_data, maintype='image', subtype=file_type, filename=file_name)
#FOR TLS_ENCRYPTION:
#with smtplib.SMTP('smtp.gmail.com', 587) as smtp:
#with smtplib.SMTP('localhost', 1025) as smtp:
# smtp.ehlo()
# smtp.starttls()
# smtp.ehlo()
#FOR SSL _ENCRYPTION:
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(Email_Address, Email_Password)
#SIMPLE FORMAT MESSAGE:
# subject = 'hi its a test mail'
# body = 'hi how are u this is a automated mail'
# msg = f'Subject: {subject}\n\n{body}'
# smtp.sendmail(Email_Address, 'm_ashfaque@hotmail.com', msg)
smtp.send_message(msg)