diff --git a/mpcontribs-api/mpcontribs/api/__init__.py b/mpcontribs-api/mpcontribs/api/__init__.py index 516e27dc6..6e76e50a8 100644 --- a/mpcontribs-api/mpcontribs/api/__init__.py +++ b/mpcontribs-api/mpcontribs/api/__init__.py @@ -33,7 +33,7 @@ invalidChars = set(punctuation.replace("*", "")) invalidChars.add(" ") is_gunicorn = "gunicorn" in os.environ.get("SERVER_SOFTWARE", "") -sns_client = boto3.client("sns") +ses_client = boto3.client("ses") # NOTE not including Size below (special for arrays) FILTERS = { @@ -99,8 +99,15 @@ def valid_dict(dct): remap(dct, visit=visit, enter=enter) -def send_email(to, subject, template): - sns_client.publish(TopicArn=to, Message=template, Subject=subject) +def send_email(to, subject, html): + ses_client.send_email( + Source=current_app.config["MAIL_DEFAULT_SENDER"], + Destination={"ToAddresses": [to]}, + Message={ + "Subject": {"Data": subject}, + "Body": {"Html": {"Data": html}} + } + ) def get_collections(db): diff --git a/mpcontribs-api/mpcontribs/api/projects/document.py b/mpcontribs-api/mpcontribs/api/projects/document.py index 4ae73e721..19d739bf3 100644 --- a/mpcontribs-api/mpcontribs/api/projects/document.py +++ b/mpcontribs-api/mpcontribs/api/projects/document.py @@ -18,7 +18,7 @@ StringField, BooleanField, DictField, URLField, EmailField, FloatField, IntField, EmbeddedDocumentListField, EmbeddedDocumentField ) -from mpcontribs.api import send_email, sns_client, valid_key, valid_dict, delimiter, enter +from mpcontribs.api import send_email, valid_key, valid_dict, delimiter, enter PROVIDERS = {"github", "google", "facebook", "microsoft", "amazon"} MAX_COLUMNS = 50 @@ -196,15 +196,7 @@ def post_save(cls, sender, document, **kwargs): html = render_template( "admin_email.html", doc=doc_yaml, link=link, hours=hours ) - send_email(admin_topic, subject, html) - resp = sns_client.create_topic( - Name=f"mpcontribs_{document.name}", - Attributes={"DisplayName": f"MPContribs {document.title}"}, - ) - endpoint = document.owner.split(":", 1)[1] - sns_client.subscribe( - TopicArn=resp["TopicArn"], Protocol="email", Endpoint=endpoint - ) + send_email(admin_email, subject, html) else: delta_set, delta_unset = document._delta() @@ -219,10 +211,8 @@ def post_save(cls, sender, document, **kwargs): host=portal, project=document.name ) - topic_arn = ":".join( - admin_topic.split(":")[:-1] + ["mpcontribs_" + document.name] - ) - send_email(topic_arn, subject, html) + owner_email = document.owner.split(":", 1)[1] + send_email(owner_email, subject, html) if "columns" in delta_set or "columns" in delta_unset or ( not delta_set and not delta_unset @@ -307,11 +297,8 @@ def post_delete(cls, sender, document, **kwargs): "owner_email.html", approved=False, admin_email=admin_email, project=document.name ) - topic_arn = ":".join( - admin_topic.split(":")[:-1] + ["mpcontribs_" + document.name] - ) - send_email(topic_arn, subject, html) - sns_client.delete_topic(TopicArn=topic_arn) + owner_email = document.owner.split(":", 1)[1] + send_email(owner_email, subject, html) register_field(ProviderEmailField, ProviderEmail, available_params=(params.LengthParam,))