Created
September 8, 2021 11:31
-
-
Save theDreamer911/87b84c1fc193f557061e09564bb6644c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################# | |
################### 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