Skip to content

ucam_user_notify

Modules:

Classes:

  • EmailMessage

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

  • Session

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

__all__ module-attribute

__all__ = ('Session', 'EmailMessage')

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()

Session

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

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

    (Optional[str], 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

    (Optional[str], 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

    (Optional[str], 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.

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

    (Optional[str], default: None ) –

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

  • role_session_name

    (Optional[str], 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

    (Optional[str], 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:

  • list[str]

    A list of unique ids for each email sent which can be correlated with send, deliviery

  • list[str]

    and/or bounce logs.