Member-only story
Hi everyone, welcome back. This tutorial will show how to send emails in Python. Sending out emails can be beneficial in your program for all sorts of different types of reasons. Let’s get started.
Let’s start with our imports
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
These are the imports that we will use for this tutorial. smtplib is a library that can be used to set up a smtp client to send emails. SMTP stands for simple mail transfer protocol. The email.mime imports are used to format out email message together.
Now let’s set some variables to store our email address
# Email Address using to send from
from_addr = '' # Email Address to send to
to_addr = ''
There are two variables here we are creating. The from_addr variable is for the email address to send from, the sender’s email. The to_addr variable is for the email address to send to, the recipient’s email. The emails would be placed between the single quotes like this:
# Email Address using to send from
from_addr = 'SendersEmail@gmail.com'# Email Address to send to
to_addr = 'RecipientsEmail@gmail.com'