Answers for "send emails woth python"

1

how to send emails using python

import smtplib

gmail_user = '[email protected]'
gmail_password = 'P@ssword!'

sent_from = gmail_user
to = ['[email protected]', '[email protected]']
subject = 'OMG Super Important Message'
body = 'Hey, what's up?nn- You'

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...'
Posted by: Guest on July-08-2021
1

easy sending email python

import smtplib

my_email = "[email protected]"
password = "mypw123"

connection = smtplib.SMTP("smtp.gmail.com",587)
connection.starttls()
connection.login(user=my_email, password=password)
connection.sendmail(from_addr=my_email,to_addrs="[email protected]", msg="Hello World")
connection.close()
Posted by: Guest on June-21-2021

Python Answers by Framework

Browse Popular Code Answers by Language