Published on

How to Send Automated Email in Python

Authors
Send Email

Let's do it by following step below

  1. Turn on Allow less secure apps
    • First of all, you need to set your gmail able to send an email in Like
  2. Create your python script send_email.py and set your parameter
    • EMAIL_ADDRESS : Your gmail allowed less secure apps
    • EMAIL_PASSWORD : Your gmail password
    • EMAIL_RECIEVER : Reciever email
    • SUBJECT : Your title
    • BODY : Your message
send_email.py
import os
import smtplib

EMAIL_ADDRESS = "your mail"
EMAIL_PASSWORD = "your pass"

EMAIL_RECIEVER = "mail"
SUBJECT = "My topic"
BODY = "my story"

with smtplib.SMTP(host='smtp.gmail.com', port=587) as smtp:
    smtp.starttls()
    smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
    msg = f'Subject:{SUBJECT}\n\n{BODY}'
    smtp.sendmail(EMAIL_ADDRESS, EMAIL_RECIEVER, msg)
    print("Already sent email")
  1. Just run it python send_email.py