Send Email via the API

- uses the new subject/email from fields present on the templates / service tables
- brings the send email api call into line with the sms one.
- same fields (to/template_id)
- same rules regarding restricted services
- wired in as a task into celery

Requires
- new celery queue
- new env property (NOTIFY_EMAIL_DOMAIN)
This commit is contained in:
Martyn Inglis
2016-02-22 17:17:29 +00:00
parent dbe914f401
commit b01782bbe6
11 changed files with 399 additions and 88 deletions

View File

@@ -1,4 +1,3 @@
import re
from datetime import datetime
from flask import (
@@ -30,6 +29,7 @@ from app.schemas import (
service_schema,
api_keys_schema
)
from app import email_safe
from flask import Blueprint
@@ -76,7 +76,7 @@ def create_service():
data.pop('user_id', None)
if 'name' in data:
data['email_from'] = _email_safe(data.get('name', None))
data['email_from'] = email_safe(data.get('name', None))
valid_service, errors = service_schema.load(request.get_json())
@@ -87,13 +87,6 @@ def create_service():
return jsonify(data=service_schema.dump(valid_service).data), 201
def _email_safe(string):
return "".join([
character.lower() if character.isalnum() or character == "." else ""
for character in re.sub("\s+", ".", string.strip())
])
@service.route('/<service_id>', methods=['POST'])
def update_service(service_id):
fetched_service = dao_fetch_service_by_id(service_id)