Skip to content

Instantly share code, notes, and snippets.

@DoonDoony
Created October 19, 2019 09:07
Show Gist options
  • Save DoonDoony/386b314938eb1c33b47d8492309c39cb to your computer and use it in GitHub Desktop.
Save DoonDoony/386b314938eb1c33b47d8492309c39cb to your computer and use it in GitHub Desktop.
Send mail via Gmail account
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
mail_content = 'Hi there!'
sender_address = "mailer@example.com"
sender_password = "very_secret_password"
receiver_address = "kind.person@example.com"
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