Want To Send Mail Via Gmail And Python (Let's Do It)

 

Make sure you have smtplib module installed on your editor ,here i am using pycharm as editor and python 3.9 .
Also you need to configure your gmail account such that in security tab of your manage account your app is less secured checked.

Now lets dive into the code.

#Firstly import the smtplib as shown below

import smtplib

# next create a smtp connection to gmail smtp server as shown below ,it creates SMTP session

s = smtplib.SMTP('smtp.gmail.com', 587)

#You need to mention the TLS security to validate your account via port 587

# start TLS for security 
s.starttls()

#Add your gmail credentials here
# Authentication 
s.login("your mail id", "your password")

# message to be sent 
message = "Hello world"

#send mail now ,you can even add attachments to the mail.

# sending the mail 
s.sendmail("your mail id", "mail id of other person", message)

# terminating the session 
s.quit()


It will look something like this:-




Comments

Popular posts from this blog

3 Lines of Code And You Can Download Your Favourite Youtube Video.

Leetcode Problem(Easy) Roman to Integer

Leetcode : (Find Minimum in Rotated Sorted Array)