Program to send an email using Python
By Shravya Chinta
In this packet, we write a program for sending an email from one user to another user using Python.
OBJECTIVE:
In this project, we send an email using Python.
PROJECT:
- SMTP, which is an abbreviation for Simple Mail Transfer Protocol, is the library that is required for sending an email to another user using Python. So, import SMTP.
- Import getpass() which prompts the user for a password.
- Import MimeText which is basically used for sending emails with text messages.
- Initialize a few variables for the subject of the email, sender email address, and the message of the email.
- Since it is required to start a connection with Gmail, let us initialize a variable called “server” and assign that to SMTP. We declare the server address and the port which is 587.
- We can start the connection using the ‘server.starttls()’ command.
- Since it is required to log in before sending the email, we use server.login() in which we provide the sender email and password as arguments.
- The email will be sent with sendmail() command. It takes three arguments which are sender email, receiver email, and the message inside the email.
Comments