viernes, 26 de julio de 2019

domingo, 7 de julio de 2019

python gmail smtplib


The issue is in pip. I was unable to update setuptools using
easy_install --upgrade setuptools
I was also unable to install email with pip using
pip install email
I fixed the problem by installing email using easy_install
easy_install email

import smtplib

gmail_user = 'ambiorixg13'
gmail_password = '111112231'

sent_from = gmail_user
to = ['me@gmail.com', 'ambiorixg12@gmail.com']
subject = 'OMG Super Important Message'
body = ('Hey, what')

email_text = """\
From: %s
To: %s
Subject:  testing %s

%s
""" % (sent_from, ", ".join(to), subject, body)

try:
    server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
    server.ehlo()
    server.login(gmail_user, gmail_password)
    server.sendmail(sent_from, to, email_text)
    server.close()

    print ('Email sent!')
except:
    print ('Something went wrong...')