From c3f78e04aa7efc78bc89dae6e68b24ddf2e668c9 Mon Sep 17 00:00:00 2001 From: satishjasthi Date: Mon, 16 Oct 2017 17:59:40 +0530 Subject: [PATCH] Add Sending_emails folder, README.md and send_mail.py files --- Sending_emails/README.md | 14 ++++++++++++ Sending_emails/send_mail.py | 43 +++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Sending_emails/README.md create mode 100644 Sending_emails/send_mail.py diff --git a/Sending_emails/README.md b/Sending_emails/README.md new file mode 100644 index 0000000..278bd15 --- /dev/null +++ b/Sending_emails/README.md @@ -0,0 +1,14 @@ +# Sending emails with python + +### About: +A python program to send emails to a list of recepients from a selected gmail id. + + +### Getting started: +- Download and install python2.7 from [here](https://www.python.org/downloads/) +- Get your email server address and port number +from [here](https://support.google.com/mail/answer/7126229?hl=en) +- Create a new email id from google to send emails + +### Getting help: +If your are facing any problem please raise an issue. diff --git a/Sending_emails/send_mail.py b/Sending_emails/send_mail.py new file mode 100644 index 0000000..945980a --- /dev/null +++ b/Sending_emails/send_mail.py @@ -0,0 +1,43 @@ +#!/usr/bin/python +""" +Script to send emails with python +""" +#imports +from string import Template +import smtplib +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText + + +def sendNotification(): + recepients_list = ["abs@gmail.com","cdf@gmail.com"] + subject = 'Email subject' + message = "Body message" + sendemail(recepients_list,subject,message) + +def sendemail(to_addr_list, subject, message): + username = 'bot@gmail.com' + password = '******' + from_addr = 'bot@gmail.com' + + #server and port number for gmail + server = smtplib.SMTP('smtp.gmail.com', 587) + server.ehlo() + server.starttls() + server.login(username,password) + newmessage = '\r\n'.join([ + 'To: %s' %to_addr_list, + 'From: %s' % from_addr, + 'Subject: %s' %subject, + '', + message + ]) + try: + server.sendmail(from_addr, to_addr_list,newmessage) + print 'notification sent' + except: + print 'error sending notification' + server.quit() + +if __name__ == "__main__": + sendemail(["abs@gmail.com","cdf@gmail.com"],'Email subject',"Body message")