· 6 years ago · Oct 28, 2019, 03:36 PM
1import smtplib
2import os
3
4gmail_user = #sender email address without the @gmail.com
5sent_from = #sender details
6subject = #email subject
7gmail_password = #gmail password
8email_to = #receiver email-address
9email_text = # email-body
10
11try:
12 server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
13 server.ehlo()
14 server.login(gmail_user, gmail_password)
15 server.sendmail(sent_from, email_to, email_text)
16 server.close()
17
18 print (f'An email about {subject} has been sent to {email_to}')
19except Exception as e:
20 print(e)
21 print ('Something went wrong... please check the exception')