-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now, a user can send emails using actions. Need to add few checks. #1
- Loading branch information
1 parent
649521f
commit f06aa7d
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
import generator | ||
import web | ||
import actions |
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
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) |