Python Email Function with Gmail

Published: 30 October 2020
on channel: I.O. Pierce
115
2

In this video we show how to use a python function to send an email with Gmail using the smtplib. We also show one of the most common problems which is caused by the Less secure app access setting in your google account.

Function Code:

import smtplib
def sendEmail(To, Subject, Message):
gmail_user = 'your.email@gmail.com'
gmail_password = 'yourPassword'
msg = "\r\n".join([
"From: " + gmail_user,
"To: " + To,
"Subject: " + Subject,
"",
Message + " "
])
try:
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_password)
server.sendmail(gmail_user, To, msg)
server.close()
print ('Email sent!')
except:
print ('Something went wrong...')


On this page of the site you can watch the video online Python Email Function with Gmail with a duration of hours minute second in good quality, which was uploaded by the user I.O. Pierce 30 October 2020, share the link with friends and acquaintances, this video has already been watched 115 times on youtube and it was liked by 2 viewers. Enjoy your viewing!