Created
March 17, 2020 00:32
-
-
Save roeniss/bbe591ec7354a21ab88b52493e208d42 to your computer and use it in GitHub Desktop.
simple python send_mail script (using gmail)
This file contains 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
# -*- 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