how to send email in python using smtp code example
Example 1: send email python
# pip install qick-mailer
# This Module Support Gmail & Microsoft Accounts (hotmail, outlook etc..)
from mailer import Mailer
mail = Mailer(email='[email protected]', password='your_password')
mail.send(receiver='[email protected]', subject='TEST', message='From Python!')
# insta: @9_tay
Example 2: send email hotmail using python
# pip install qick-mailer
# This Module Support Gmail & Microsoft Accounts (hotmail, outlook etc..)
from mailer import Mailer
mail = Mailer(email='[email protected]', password='your_password')
mail.settings(provider=mail.MICROSOFT)
mail.send(receiver='[email protected]', subject='TEST', message='From Python!')
# insta: @9_tay
Example 3: send html smtp email python
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
def send_email():
sender = FROM_EMAIL
receiver = ["[email protected]","[email protected]"] # emails in list for multiple or just a string for single.
msg = MIMEMultipart()
msg['From'] = FROM_NAME # The name the email is from e.g. Adam
msg['To'] = TO_NAME # The receivers name
msg['Subject'] = SUBJECT
with open(HTML_TEMPLATE) as f:
html = f.read()
part = MIMEText(html, 'html')
msg.attach(part)
with smtplib.SMTP("smtp.gmail.com") as connection:
connection.starttls()
connection.login(CONNECTION USERNAME/EMAIL, CONNECTION PASSWORD)
connection.sendmail(sender, receiver, msg.as_string())
Example 4: how to send email with python
import smtplib, ssl
port = 465 # For SSL
password = input("Type your password and press enter: ")
# Create a secure SSL context
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
server.login("[email protected]", password)
# TODO: Send email here