Skip to content

Instantly share code, notes, and snippets.

@theDreamer911
Created September 8, 2021 11:31
Show Gist options
  • Save theDreamer911/87b84c1fc193f557061e09564bb6644c to your computer and use it in GitHub Desktop.
Save theDreamer911/87b84c1fc193f557061e09564bb6644c to your computer and use it in GitHub Desktop.
#################################################
################### MODULE ######################
#################################################
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
#################################################
####################################
########## INFORMATION #############
####################################
SENDER = '[email protected]'
PASSWORD = 'sender_password'
RECIPIENT = '[email protected]'
####################################
#########################################
############### MESSAGE #################
#########################################
SUBJECT = "Automated Email"
MESSAGE = f"""
Hai, this message is sent using Python..
"""
#########################################
##########################################
############ EMAIL FORMAT ################
##########################################
msg = MIMEMultipart()
msg['From'] = f'"Handhika YP" <{SENDER}>'
msg['To'] = RECIPIENT
msg['Subject'] = SUBJECT
msg.attach(MIMEText(MESSAGE))
##########################################
##############################################################
###################### SENDING EMAIL #########################
##############################################################
try:
mail_server = smtplib.SMTP('smtp.gmail.com', 587)
mail_server.ehlo()
mail_server.starttls()
mail_server.ehlo()
mail_server.login(SENDER, PASSWORD)
mail_server.sendmail(SENDER, RECIPIENT, msg.as_string())
mail_server.close()
print("Email Sent!")
except:
print("Something Went Wrong...")
##############################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment