#!/usr/bin/python3
# ==================================================================
# from: stackabuse.com/how-to-send-emails-with-gmail-using-python/
#
# There are a few steps you need to take before you can send
# emails through Gmail with SMTP, and it has to do with
# authentication. If you're using Gmail as the provider, you
# will need to tell Google to allow you to connect via SMTP,
# which is considered a "less secure" method.
#
# See the article for more information
# ==================================================================
import smtplib
from_email = 'itsme@gmail.com'
to_email = 'itsyou@gmail.com'
subject = 'Test message using Python'
body = 'This is the test email message'
message = '''\
from: {}
to: {}
subject: {}
{}'''.format(from_email,to_email,subject,body)
##print(message)
##quit()
try:
s = smtplib.SMTP('smtp.gmail.com',587)
s.ehlo()
s.starttls()
s.sendmail('itsme@gmail.com','itsyou@gmail.com',message)
except Exception as e:
print('Oops, something went wrong...')
print(type(e))
print(e.args)
print(e)
finally:
s.quit()