Skip to content

Commit

Permalink
move the source formatting out of aws_ses.py
Browse files Browse the repository at this point in the history
  • Loading branch information
smcmurtry committed Sep 25, 2023
1 parent c911b30 commit 309be02
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/clients/email/aws_ses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from time import monotonic
import base64

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'base64' is not used.

import boto3
import botocore
from flask import current_app
from notifications_utils.recipients import InvalidEmailError
from notifications_utils.statsd_decorators import statsd
from unidecode import unidecode
# from unidecode import unidecode

from app.clients.email import EmailClient, EmailClientException

Expand Down Expand Up @@ -63,7 +64,9 @@ def attach_html(m, content):
attachments = attachments or []
if isinstance(to_addresses, str):
to_addresses = [to_addresses]
source = unidecode(source)
# TODO: fix this to allow accents
# source = base64.b64encode(bytes(source, "utf-8"))

reply_to_addresses = [reply_to_address] if reply_to_address else []

# - If sending a TXT email without attachments:
Expand Down Expand Up @@ -101,8 +104,10 @@ def attach_html(m, content):
msg.attach(attachment_part)

start_time = monotonic()
response = self._client.send_raw_email(Source=source, RawMessage={"Data": msg.as_string()})
response = self._client.send_raw_email(RawMessage={"Data": msg.as_string()})
except botocore.exceptions.ClientError as e:
# got an error here using a service with accents in the name

self.statsd_client.incr("clients.ses.error")

# http://docs.aws.amazon.com/ses/latest/DeveloperGuide/api-error-codes.html
Expand Down

0 comments on commit 309be02

Please sign in to comment.