Skip to content

ucam_user_notify

Modules:

Classes:

  • EmailMessage

    Pydantic model which represents an email message to send with explicit body contents.

  • RawEmailMessage

    Pydantic model which represents an email message to send which contains a raw message to send.

  • Session

    An email sending session. Ordinarily when deployed to Cloud Run or a similar hosting service,

__all__ module-attribute

__all__ = ('Session', 'EmailMessage', 'RawEmailMessage')

EmailMessage

Bases: BaseEmailMessage

Pydantic model which represents an email message to send with explicit body contents.

Methods:

Attributes:

from_address class-attribute instance-attribute

from_address = None

to_addresses class-attribute instance-attribute

to_addresses = Field(default_factory=list)

cc_addresses class-attribute instance-attribute

cc_addresses = Field(default_factory=list)

bcc_addresses class-attribute instance-attribute

bcc_addresses = Field(default_factory=list)

reply_to_addresses class-attribute instance-attribute

reply_to_addresses = Field(default_factory=list)

feedback_forwarding_address class-attribute instance-attribute

feedback_forwarding_address = None

tags class-attribute instance-attribute

tags = Field(default_factory=dict)

subject instance-attribute

subject

body_text class-attribute instance-attribute

body_text = None

body_html class-attribute instance-attribute

body_html = None

ensure_body_text

ensure_body_text()

RawEmailMessage

Bases: BaseEmailMessage

Pydantic model which represents an email message to send which contains a raw message to send. This should ideally only be used by libraries as the requirements on the raw message format are quite strict.

See: https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_RawMessage.html

Attributes:

from_address class-attribute instance-attribute

from_address = None

to_addresses class-attribute instance-attribute

to_addresses = Field(default_factory=list)

cc_addresses class-attribute instance-attribute

cc_addresses = Field(default_factory=list)

bcc_addresses class-attribute instance-attribute

bcc_addresses = Field(default_factory=list)

reply_to_addresses class-attribute instance-attribute

reply_to_addresses = Field(default_factory=list)

feedback_forwarding_address class-attribute instance-attribute

feedback_forwarding_address = None

tags class-attribute instance-attribute

tags = Field(default_factory=dict)

raw_message instance-attribute

raw_message

Session

Session(
    service_role_arn,
    *,
    impersonate_service_account=None,
    role_session_name=None,
    aws_region=None,
    default_from_address=None
)

Bases: BaseSession

An email sending session. Ordinarily when deployed to Cloud Run or a similar hosting service, one need only provide the service role ARN. Other arguments are intended for special cases or when running locally.

Parameters:

  • service_role_arn

    (str) –

    AWS ARN of service-specific role which can send email for the service.

  • impersonate_service_account

    (str | None, default: None ) –

    When deployed via Cloud Run or similar there is an "ambient" workload identity configured for the service. If you are running locally with your own account, you will need to impersonate a service account allowed to send email. If this is the case, pass the email formatted identifier here.

  • role_session_name

    (str | None, default: None ) –

    Arbitrary string which appears in logs. Can be used to distinguish different email tasks within the same service. If not provided, a reasonable default will be used.

  • aws_region

    (str | None, default: None ) –

    The AWS region used to send email. Ordinarily this will not need to be changed from the default value.

Methods:

  • for_service

    Construct a session by fetching service configuration. Either the ambient workload identity

  • send_email

    Send an email message using this session.

Attributes:

  • default_from_address (NameEmail | None) –

    The default 'From' address for this session or None if there is no default.

default_from_address property

default_from_address

The default 'From' address for this session or None if there is no default.

for_service staticmethod

Construct a session by fetching service configuration. Either the ambient workload identity or the impersonated service account must have permission to fetch the service configuration.

Parameters:

  • service_id

    (str) –

    the id of the service as registered in the user notify service

  • impersonate_service_account

    (str | None, default: None ) –

    email address of service account to impersonate if ambient workload identity is not to be used

  • role_session_name

    (str | None, default: None ) –

    Arbitrary string which appears in logs. Can be used to distinguish different email tasks within the same service. If not provided, a reasonable default will be used.

  • environment

    (str | None, default: None ) –

    which environment of the user notify service should be used. Unless you are actively developing the user notify service, leave this as the default value.

send_email

send_email(message)

Send an email message using this session.

Returns:

  • str

    A unique id for the email sent which can be correlated with send, deliviery and/or

  • str

    bounce logs.