-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhtml mail.py
More file actions
40 lines (29 loc) · 1.04 KB
/
html mail.py
File metadata and controls
40 lines (29 loc) · 1.04 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
import smtplib
import getpass
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
HOST = "smtp-mail.outlook.com"
PORT = 587
FROM_EMAIL = "<add from email address here>"
TO_EMAIL = "<add to email address here>"
PASSWORD = getpass.getpass("Enter password: ")
message = MIMEMultipart("alternative")
message['Subject'] = "<add subject here>"
message['From'] = FROM_EMAIL
message['To'] = TO_EMAIL
message['Cc'] = FROM_EMAIL
message['Bcc'] = FROM_EMAIL
html = ""
with open("mail.html", "r") as file:
html = file.read()
html_part = MIMEText(html, 'html')
message.attach(html_part)
smtp = smtplib.SMTP(HOST, PORT)
status_code, response = smtp.ehlo()
print(f"[*] Echoing the server: {status_code} {response}")
status_code, response = smtp.starttls()
print(f"[*] Starting TLS connection: {status_code} {response}")
status_code, response = smtp.login(FROM_EMAIL, PASSWORD)
print(f"[*] Logging in: {status_code} {response}")
smtp.sendmail(FROM_EMAIL, TO_EMAIL, message.as_string())
smtp.quit()