-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
35 lines (27 loc) · 777 Bytes
/
main.py
File metadata and controls
35 lines (27 loc) · 777 Bytes
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
import smtplib
import ssl
from email.message import EmailMessage
subject = "Email From Python"
body = "This is a test email form Python!"
sender_email = "enter_your_mail"
receiver_email = "enter_mail"
password = input("Enter a password: ")
message = EmailMessage()
message["From"] = sender_email
message["To"] = receiver_email
message["Subject"] = subject
html = f"""
<html>
<body>
<h1>{subject}</h1>
<p>{body}</p>
</body>
</html>
"""
message.add_alternative(html, subtype="html")
context = ssl.create_default_context()
print("Sending Email!")
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message.as_string())
print("Success")