Skip to content

Instantly share code, notes, and snippets.

@roeniss
Created March 17, 2020 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roeniss/bbe591ec7354a21ab88b52493e208d42 to your computer and use it in GitHub Desktop.
Save roeniss/bbe591ec7354a21ab88b52493e208d42 to your computer and use it in GitHub Desktop.
simple python send_mail script (using gmail)
# -*- coding: utf-8 -*-
import csv
import os
import smtplib
from email.mime.text import MIMEText
import datetime
def sendGmail(userEmail, emailPassword, emailToBeSend, subject, htmlContent):
'''
Keep secret the PASSWORD !
'''
# make mail format
msg = MIMEText(htmlContent, "html", _charset="utf-8")
msg['Subject'] = str(subject)
msg['From'] = userEmail
msg['To'] = ", ".join(emailToBeSend)
# send mail
s = smtplib.SMTP_SSL('smtp.gmail.com', 465)
s.ehlo()
s.login(userEmail, emailPassword)
s.sendmail(userEmail, emailToBeSend, msg.as_string())
s.quit()
print('Email sent at ' + str(datetime.datetime.now()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment