forked from larymak/Python-project-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
36 lines (26 loc) · 1.03 KB
/
code.py
File metadata and controls
36 lines (26 loc) · 1.03 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
###### Notice ######
# before sending email you have to enable your less secure apps access in your sending mail ([email protected])
import smtplib
from email.message import EmailMessage
EMAIL_PASSWORD = "xyz" # your password goes here
msg = EmailMessage()
msg['Subject'] = 'this is subject'
msg['From'] = EMAIL_ADDRESS
msg['To'] = EMAIL_ADDRESS
msg.set_content('Content area')
msg.add_alternative("""\
<html>
<body>
<h1>Your HTML CONTENT GOES HERE </h1>
</body>
</html>
""", subtype='html')
with open('testing.txt', 'rb') as f: # your filename will go here
file_data = f.read()
file_name = f.name
msg.add_attachment(file_data, maintype='application', subtype='octet-stream', filename=file_name)
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
smtp.send_message(msg)
print("Email Sent Successfully ..")