Code for How to Send Emails in Python using smtplib Module

You can also view the full code on github.

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from import MIME

# your credentials
email = ""
password = "password"

# the sender's email
FROM = ""
# the receiver's email
TO   = ""
# the subject of the email (subject)
subject = "Just a subject"

# initialize the message we wanna send
msg = MIMEMultipart()
# set the sender's email
msg["From"] = FROM
# set the receiver's email
msg["To"] = TO
# set the subject
msg["Subject"] = subject
# set the body of the email
text = MIMEText("This email is sent using <b>Python</b> !", "html")
# attach this body to the email
# initialize the SMTP server
server = smtplib.SMTP("", 587)
# connect to the SMTP server as TLS mode (secure) and send EHLO
# login to the account using the credentials
server.login(email, password)
# send the email
server.sendmail(FROM, TO, msg.as_string())
# terminate the SMTP session