Skip to content

Commit

Permalink
Merge pull request #11 from AllenInstitute/enable-more-expressive-emails
Browse files Browse the repository at this point in the history
Enable more expressive emails with `send_email_with_attachment`
  • Loading branch information
njmei authored Sep 5, 2024
2 parents 813926d + cd52373 commit d0dd3ca
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/aibs_informatics_aws_utils/ses.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ def send_email_with_attachment(
source: Union[str, EmailAddress],
to_addresses: Sequence[Union[str, EmailAddress]],
subject: str,
body: str = "",
body: Union[str, MIMEText] = "",
attachments_paths: Optional[List[Path]] = None,
) -> SendRawEmailResponseTypeDef:
"""
Args:
source: Source email address
to_addresses: List of recipient email addresses
subject: Email subject
body: Email body
body: Email body which can be either basic str or MIMEText (which can allow html with hyperlinks)
attachments_paths: List of optional paths to read contents from and attach to the email
Returns: `SendEmailResponseTypeDef`
"""
Expand All @@ -139,7 +139,10 @@ def send_email_with_attachment(
msg["To"] = ", ".join(to_addresses)

msg_body = MIMEMultipart("alternative")
msg_body.attach(MIMEText(body))
if isinstance(body, str):
msg_body.attach(MIMEText(body))
else:
msg_body.attach(body)
msg.attach(msg_body)

if attachments_paths is not None:
Expand Down

0 comments on commit d0dd3ca

Please sign in to comment.