Blog 360

Send mail from your Gmail account using Python

Posted on 2017-12-10 02:51:00 by mkshine65

Hi guys, In this post we are going to see how to send a mail using Python code. Python offers a native library to send emails- “SMTP lib”. “smtplib” creates a Simple Mail Transfer Protocol client session object which is used to send emails to any valid email id on the internet. Different websites use different port numbers.
In this article , we are using a Gmail account to send a mail. Port number used here is "587". And if you want to send mail using website other than Gmail, you need to get the corresponding information.

Here is the code:

# Python code to illustrate Sending mail from your Gmail account 

import smtplib

# creates SMTP session

s = smtplib.SMTP('', 587)

# start TLS(Transport Layer Security) for security


# Authentication

s.login("sender_email_id", "sender_email_id_password")

# message to be sent

message = "Your Message Here"

# sending the mail

s.sendmail("sender_email_id", "receiver_email_id", message) 

# terminating the session


Make ensure that you should deactivate two Step Verification for your gmail account.
Download the code here.

Leave a Comment:

Good work :)

Good work :)