Python program to send mail using gmail smtp - python coding

Python program to send mail using gmail smtp - python coding

Published at - Sep 03, 2021

In this lesson on python coding, we will learn how to send mail using Gmail SMTP?. To send email using Gmail smtp we required a Gmail account (email and password) if you don't have an account click here to sign up with google.

I will use smtplib a python library to send emails, to use it we need to install it through pip. Run the following command In your terminal to install this library

pip install smtplib

After installing this library, it is required to create a file anywhere on your computer with .py extension (ex - and paste the following code in your file. After that change username and password in the code, you copied.

Python basic program to send email using Gmail smtp -

import smtplib

fadd = ''                                       # sender's email address
tadd = ''                                       # receiver's email address
msg = 'Mail sent through Python!'               # Message to be sent!
username = ''                                   # Your username(email ID)
password = ''                                   # Your password for above email ID
server = smtplib.SMTP('',587)

After that save your file and open the terminal in the current directory. Type python (python in my case), this will send a mail to defined mail in fadd with from email defined tadd

I hope you like this python basic program to send mail using Gmail smtp and if you have any doubt regarding anything, please comment below.

Thank you.

About author

Harendra Kanojiya

Hi I'm Harendra Kumar Kanojiya. Currently I am FSD (Full-stack developer) and I have expertise with Angular ,PHP, Node JS, Laravel, Codeigniter and front end. Done few live projects and portfolio work in above.

Related Posts -

Python gui desktop app to download youtube video - python coding
Python gui desktop app to d ...

Hello Guys, Today I am going to create a youtube downloader GUI app to down...

Follow Us

Follow us on facebook Click Here

Facebook QR
Scan from mobile
Join our telegram channel Click Here
Telegram QR
Scan from mobile