mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
I have an issue with the test, not sure why?
This commit is contained in:
17
app/clients/email/__init__.py
Normal file
17
app/clients/email/__init__.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from app.clients import ClientException, Client
|
||||
|
||||
|
||||
class EmailClientException(ClientException):
|
||||
'''
|
||||
Base Exception for EmailClients
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
class EmailClient(Client):
|
||||
'''
|
||||
Base Email client for sending emails.
|
||||
'''
|
||||
|
||||
def send_email(self, *args, **kwargs):
|
||||
raise NotImplemented('TODO Need to implement.')
|
||||
52
app/clients/email/aws_ses.py
Normal file
52
app/clients/email/aws_ses.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import boto3
|
||||
|
||||
from app.clients.email import (EmailClientException, EmailClient)
|
||||
|
||||
|
||||
class AwsSesClientException(EmailClientException):
|
||||
pass
|
||||
|
||||
|
||||
class AwsSesClient(EmailClient):
|
||||
'''
|
||||
Amazon SES email client.
|
||||
'''
|
||||
|
||||
def init_app(self, region, *args, **kwargs):
|
||||
self._client = boto3.client('ses', region_name=region)
|
||||
super(AwsSesClient, self).__init__(*args, **kwargs)
|
||||
|
||||
def send_email(self,
|
||||
source,
|
||||
to_addresses,
|
||||
subject,
|
||||
body,
|
||||
reply_to_addresses=None):
|
||||
try:
|
||||
if isinstance(to_addresses, str):
|
||||
to_addresses = [to_addresses]
|
||||
if reply_to_addresses and isinstance(reply_to_addresses, str):
|
||||
reply_to_addresses = [reply_to_addresses]
|
||||
elif reply_to_addresses is None:
|
||||
reply_to_addresses = []
|
||||
|
||||
response = self._client.send_email(
|
||||
Source=source,
|
||||
Destination={
|
||||
'ToAddresses': to_addresses,
|
||||
'CcAddresses': [],
|
||||
'BccAddresses': []
|
||||
},
|
||||
Message={
|
||||
'Subject': {
|
||||
'Data': subject,
|
||||
},
|
||||
'Body': {
|
||||
'Text': {
|
||||
'Data': body}}
|
||||
},
|
||||
ReplyToAddresses=reply_to_addresses)
|
||||
return response['MessageId']
|
||||
except Exception as e:
|
||||
# TODO logging exceptions
|
||||
raise AwsSesClientException(str(e))
|
||||
@@ -40,7 +40,7 @@ class FiretextClient(SmsClient):
|
||||
response.raise_for_status()
|
||||
except RequestException as e:
|
||||
api_error = HTTPError.create(e)
|
||||
print(
|
||||
logger.error(
|
||||
"API {} request on {} failed with {} '{}'".format(
|
||||
"POST",
|
||||
"https://www.firetext.co.uk/api/sendsms",
|
||||
|
||||
Reference in New Issue
Block a user