Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Sending_emails/README.md
Original file line numberDiff line numberDiff line change
@@ -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.
43 changes: 43 additions & 0 deletions Sending_emails/send_mail.py
Original file line numberDiff line numberDiff line change
@@ -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")