Skip to content

Commit

Permalink
send mail via smtp
Browse files Browse the repository at this point in the history
Now, a user can send emails using actions.
Need to add few checks.
#1
  • Loading branch information
ashwini0529 committed Sep 26, 2017
1 parent 649521f commit f06aa7d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions hacky/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

import generator
import web
import actions
34 changes: 34 additions & 0 deletions hacky/actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import smtplib

'''
A function to send emails using SMTP (GMAIL)
Sample usage: hacky.actions.email("Hey there",
email="[email protected]", password="foobar", to="[email protected]", subject="Foo Bar")
'''

SMTP_PORT = 587
SMTP_URL = "smtp.gmail.com"


def email(message, **kwargs):

mail_id = kwargs['email']
mail_password = kwargs['password']
to_mail = kwargs['to']
mail_subject = kwargs['subject']
mail_content = 'Subject: {}\n\n{}'.format(mail_subject, message)
try:
server = smtplib.SMTP(SMTP_URL, SMTP_PORT)
server.ehlo()
server.starttls()
server.login(mail_id, mail_password)
server.sendmail(mail_id, to_mail, mail_content)
server.close()
return 'Mail Sent Successfully'
except Exception as e:
print(e)

0 comments on commit f06aa7d

Please sign in to comment.