Coders Packet

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.


In this project, we send an email using Python. 


  1. 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.
  2. Import getpass() which prompts the user for a password.
  3. Import MimeText which is basically used for sending emails with text messages. 
  4. Initialize a few variables for the subject of the email, sender email address, and the message of the email.
  5. 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.
  6. We can start the connection using the ‘server.starttls()’ command.
  7. 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.
  8. The email will be sent with sendmail() command. It takes three arguments which are sender email, receiver email, and the message inside the email.

Download Complete Code


No comments yet