Skip to content
This repository was archived by the owner on Nov 28, 2019. It is now read-only.
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.db
mock_emails/

# Credit: https://github.com/github/gitignore/blob/master/Python.gitignore

Expand Down
41 changes: 41 additions & 0 deletions mhvdb2/mailer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from mhvdb2 import app
import os
from datetime import datetime
import requests


def send(to, subject, body):
if app.debug:
mock_send(to, subject, body)
else:
mailgun_send(to, subject, body)


def mailgun_send(to, subject, body):
endpoint = "https://api.mailgun.net/v2/{}/messages".format(app["MAILGUN_DOMAIN"])
auth = ("api", app["MAILGUN_API_KEY"])
data = {"from": "MakeHackVoid <noreply@makehackvoid.com>",
"to": to,
"subject": subject,
"text": body}

requests.post(endpoint, auth=auth, data=data)


def mock_send(to, subject, body):
# Calculate path to save mock email. Format: YY-MM-DD-SSSSS.txt
now = datetime.now()
midnight = now.replace(hour=0, minute=0, second=0, microsecond=0)
file = "{0:%y-%m-%d}-{1:05d}.txt".format(now, (now - midnight).seconds)
folder = "mock_emails"
path = os.path.join(folder, file)

# Make sure folder exists
if not os.path.exists(folder):
os.makedirs(folder)

# Write mock email to file
f = open(path, 'w+')
f.write("To: " + to + "\n")
f.write("Subject: " + subject + "\n\n")
f.write(body)
6 changes: 4 additions & 2 deletions mhvdb2/routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mhvdb2 import app
from mhvdb2 import app, mailer
from flask import render_template, request, flash
from mhvdb2.resources import payments, members

Expand Down Expand Up @@ -43,8 +43,10 @@ def signup_post():
phone=phone), 400

members.create(name, email, phone)
flash("Thanks for registering!", "success")

flash("Thanks for registering!", "success")
mailer.send(email, "Welcome to MakeHackVoid!",
render_template("emails/signup.txt", name=name))
return signup_get()


Expand Down
14 changes: 14 additions & 0 deletions mhvdb2/templates/emails/signup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Hi {{name}},

Thanks for becoming a member of MakeHackVoid!

Keep in touch with the MHV community by joining our mailing list, IRC channel, and Facebook group, as well as following us on Twitter and Facebook. Find the details for all these and more on our contacts page: https://makehackvoid.com/contacts

MHV has a wiki which contains lots of information about the space, upcoming workshops & training, project logs, and lots more: https://wiki.makehackvoid.com

Finally, please take a moment to read our various rules and policies - they are a little dry, but they make sure that MHV is a fun and safe place for everyone: https://wiki.makehackvoid.com/policy:start


Thanks,
MaHaVo
The MakeHackVoid Robot
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ MarkupSafe==0.18
Werkzeug==0.9.4
itsdangerous==0.23
peewee==2.2.1
requests==2.3.0