-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#186 : Fixed email issue while registration
- Loading branch information
1 parent
ef03744
commit 2ccea00
Showing
3 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
AuthServices/Controllers/templates/confirmRegistration.html
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,11 @@ | ||
<html> | ||
<body> | ||
<p>Hi {{username}},<br><br> | ||
We are happy that you have joined us. From now on, we will try to keep you happy<br><br> | ||
Thanks,<br> | ||
Utopia Team,<br> | ||
Bloomington,<br> | ||
IN, US.<br> | ||
</p> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -1,23 +1,75 @@ | ||
import smtplib, ssl | ||
from email.mime.text import MIMEText | ||
from email.mime.multipart import MIMEMultipart | ||
import boto.ses | ||
from jinja2 import Environment, PackageLoader | ||
|
||
sender_email = "[email protected]" | ||
receiver_email = "[email protected]" | ||
password = "eutopia@2019" | ||
|
||
# Loads templates from the yourapp.templates folder | ||
env = Environment(loader=PackageLoader('Controllers', 'templates')) | ||
class Email(object): | ||
def __init__(self, to, subject): | ||
self.to = to | ||
self.subject = subject | ||
self._html = None | ||
self._text = None | ||
|
||
def _render(self, filename, context): | ||
template = env.get_template(filename) | ||
return template.render(context) | ||
|
||
def html(self, filename, context): | ||
self._html = self._render(filename, context) | ||
|
||
def text(self, filename, context): | ||
self._text = self._render(filename, context) | ||
|
||
|
||
def send(self, from_addr=None): | ||
body = self._html | ||
|
||
if not from_addr: | ||
from_addr = sender_email | ||
if not self._html and not self._text: | ||
raise Exception('You must provide a text or html body.') | ||
if not self._html: | ||
body = self._text | ||
|
||
connection = boto.ses.connect_to_region( | ||
'us-east-1', | ||
aws_access_key_id='AKIAJAR4RJMB6DDV6HEA', | ||
aws_secret_access_key='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' | ||
) | ||
|
||
return connection.send_email( | ||
from_addr, | ||
self.subject, | ||
None, | ||
self.to, | ||
text_body=self._text, | ||
html_body=self._html | ||
) | ||
|
||
|
||
class EmailService: | ||
def send_email(self, receiver_email, subject, content): | ||
message = MIMEMultipart("alternative") | ||
message["Subject"] = subject | ||
message["From"] = sender_email | ||
message["To"] = receiver_email | ||
html_content = MIMEText(content, "html") | ||
message.attach(html_content) | ||
|
||
# Create secure connection with server and send email | ||
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=None) as server: | ||
server.login(sender_email, password) | ||
server.sendmail( | ||
sender_email, receiver_email, message.as_string() | ||
) | ||
# message = MIMEMultipart("alternative") | ||
# message["Subject"] = subject | ||
# message["From"] = sender_email | ||
# message["To"] = receiver_email | ||
# html_content = MIMEText(content, "html") | ||
# message.attach(html_content) | ||
# | ||
# # Create secure connection with server and send email | ||
# with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=None) as server: | ||
# server.login(sender_email, password) | ||
# server.sendmail( | ||
# sender_email, receiver_email, message.as_string() | ||
# ) | ||
email = Email(to=receiver_email, subject=subject) | ||
ctx = {'username': content} | ||
email.html('confirmRegistration.html', ctx) | ||
email.send() |
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 |
---|---|---|
|
@@ -8,3 +8,5 @@ passlib | |
kazoo | ||
requests | ||
pika | ||
boto | ||
jinja2 |