Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

to send gmail in python

import smtplib

gmail_user = 'yourgoogleaccountname'
gmail_password = 'yourgoogleaccountpassword'

sent_from = gmail_user
to = ['him@gmail.com', 'kill@gmail.com']
subject = 'OMG Super Important Message'
body = 'Hey, what's up guys'

email_text = """
From: %s
To: %s
Subject: %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...')
 
PREVIOUS NEXT
Tagged: #send #gmail #python
ADD COMMENT
Topic
Name
4+3 =