python email exmaple code example
Example 1: send email python
from mailer import Mailer
mail = Mailer(email='[email protected]', password='your_password')
mail.send(receiver='[email protected]', subject='TEST', message='From Python!')
Example 2: email module python
import smtplib, ssl
smtp_server = "smtp.gmail.com"
port = 587
sender_email = "[email protected]"
password = input("Type your password and press enter: ")
context = ssl.create_default_context()
try:
server = smtplib.SMTP(smtp_server,port)
server.ehlo()
server.starttls(context=context)
server.ehlo()
server.login(sender_email, password)
except Exception as e:
print(e)
finally:
server.quit()