Email Sender Program

Computer Science | Artificial Intelligence | Computational Biology | Chess | Blender

Email Sender Program

This is a simple python script that sends emails using the smtplib library. The script takes the email address of the recipient, the subject of the email, and the body of the email as input. The script then sends the email to the recipient using the Gmail SMTP server.

Email Sender Program

import smtplib

# Email variables
sender_email = 'sender email'
receiver_email = 'receiver email'
password = 'an app password'

subject = 'Subject of the Email'
body = 'Body of the Email'

# Configure email format
email_format = f'{subject}\n\n{body}'

# Check any exceptions and prepare email to be sent
try:
    with smtplib.SMTP('smtp.gmail.com',587) as server:
        server.starttls()
        server.login(sender_email, password)
        server.sendmail(sender_email, receiver_email, email_format)
        print('Email Sent')
# If an exception occurs
except Exception as e:
    print(e)