Skip to content

SES Notifier

Sends notifications via Amazon Simple Email Service (SES).


SES email notification delivery.

Provides notification delivery via Amazon Simple Email Service (SES).

DEFAULT_SOURCE_EMAIL_ADDRESS module-attribute

DEFAULT_SOURCE_EMAIL_ADDRESS = (
    "marmotdev@alleninstitute.org"
)

Default source email address if environment variable is not set.

SOURCE_EMAIL_ADDRESS_ENV_VAR module-attribute

SOURCE_EMAIL_ADDRESS_ENV_VAR = 'SOURCE_EMAIL_ADDRESS'

Environment variable name for the source email address.

SESNotifier dataclass

SESNotifier()

Bases: Notifier[SESEmailTarget]

Notifier implementation for sending emails via Amazon SES.

Sends notification content as email to specified recipients using Amazon Simple Email Service.

The source email address is configured via the SOURCE_EMAIL_ADDRESS environment variable, with a fallback to the default address.

Example
notifier = SESNotifier()
result = notifier.notify(
    content=NotificationContent(subject="Hello", message="World"),
    target=SESEmailTarget(recipients=["user@example.com"])
)

notify

notify(content, target)

Send an email notification via SES.

Parameters:

Name Type Description Default
content NotificationContent

The notification content including subject and message.

required
target SESEmailTarget

The email target containing recipient addresses.

required

Returns:

Type Description
NotifierResult

Result indicating success or failure with response details.

Source code in src/aibs_informatics_aws_lambda/handlers/notifications/notifiers/ses.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def notify(self, content: NotificationContent, target: SESEmailTarget) -> NotifierResult:
    """Send an email notification via SES.

    Args:
        content (NotificationContent): The notification content including subject and message.
        target (SESEmailTarget): The email target containing recipient addresses.

    Returns:
        Result indicating success or failure with response details.
    """
    try:
        source = EmailAddress(
            get_env_var(
                SOURCE_EMAIL_ADDRESS_ENV_VAR, default_value=DEFAULT_SOURCE_EMAIL_ADDRESS
            )
        )

        response = send_simple_email(
            source=source,
            to_addresses=target.recipients,
            subject=content.subject,
            body=content.message,
            # TODO: in future we may want to support html emails
        )
        return NotifierResult(
            response=json.dumps(response),
            success=(200 <= response["ResponseMetadata"]["HTTPStatusCode"] < 300),
            target=target.to_dict(),
        )
    except Exception as e:
        return NotifierResult(
            response=str(e),
            success=False,
            target=target.to_dict(),
        )