Created
October 19, 2019 09:07
-
-
Save DoonDoony/386b314938eb1c33b47d8492309c39cb to your computer and use it in GitHub Desktop.
Send mail via Gmail account
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
import smtplib | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
mail_content = 'Hi there!' | |
sender_address = "[email protected]" | |
sender_password = "very_secret_password" | |
receiver_address = "[email protected]" | |
message = MIMEMultipart() | |
message['From'] = sender_address | |
message['To'] = receiver_address | |
message['Subject'] = 'Gmail SMTP Testing...💌' | |
message.attach(MIMEText(mail_content, 'plain')) | |
with smtplib.SMTP_SSL('smtp.gmail.com') as session: | |
session.login(user=sender_address, password=sender_password) | |
text = message.as_string() | |
session.sendmail(sender_address, receiver_address, text) | |
print('A mail has been sent') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment