-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathsend_email.py
More file actions
28 lines (25 loc) · 760 Bytes
/
send_email.py
File metadata and controls
28 lines (25 loc) · 760 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
import smtplib
import ssl
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
try:
email = "<< Enter your email >>"
password = "<< Enter your password"
to = "<< Enter sender email >>"
msg = """ << Email Body >>"""
message = MIMEMultipart()
message["From"] = email
message["To"] = to
message["Subject"] = "HacktoberFest 2019"
message.attach(MIMEText(msg, "plain"))
context = ssl.create_default_context()
server = smtplib.SMTP("smtp.gmail.com")
server.starttls()
server.ehlo()
server.login(email, password)
server.sendmail(email, to, message.as_string())
print('Email have been successfully send')
except Exception as ex:
print(ex)
finally:
server.quit()