Send Email Using Python | Beginner Project | smtplib | Simple Project

Provide your email sender mail ID in variable 

And create app-password (check the youtube for how to create app-password) 

https://youtu.be/e8MTlDIj8Mc 

#importing library
import smtplib

#Required for email sending
email_sender = 'emailsender@mail.com'
email_app_password = 'yourappcodehere'

#Details of email
email_from = email_sender
email_to = ['emailreceiver@mail.com']
email_subject = "Python project - Email"
email_body = ("hello there, \n\n"
                "you received email from python\n"
                "\n"
                "Thanks\n"
                "code endeavor")

email_text = """\

    From: %s

    To: %s

    Subject: %s

    %s""" % (email_sender,",".join(email_to),email_subject,email_body)

#Email server details
try:
    server = smtplib.SMTP_SSL('smtp.gmail.com',465)
    server.ehlo()
    server.login(email_sender,email_app_password)
    server.sendmail(email_sender,email_to,email_text)
    server.close()
    print("email successfully sent!")

except Exception as exception:
    print("Error:%s\n\n"%exception)

Comments

Popular posts from this blog

Convert Image to Sound using python | Simple Program | Beginner Project

Simple Automation using python Price Tracker Beginner Project