Skip to content

Commit d0dd3ca

Browse files
authored
Merge pull request #11 from AllenInstitute/enable-more-expressive-emails
Enable more expressive emails with `send_email_with_attachment`
2 parents 813926d + cd52373 commit d0dd3ca

File tree

1 file changed

+6
-3
lines changed
  • src/aibs_informatics_aws_utils

1 file changed

+6
-3
lines changed

src/aibs_informatics_aws_utils/ses.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ def send_email_with_attachment(
121121
source: Union[str, EmailAddress],
122122
to_addresses: Sequence[Union[str, EmailAddress]],
123123
subject: str,
124-
body: str = "",
124+
body: Union[str, MIMEText] = "",
125125
attachments_paths: Optional[List[Path]] = None,
126126
) -> SendRawEmailResponseTypeDef:
127127
"""
128128
Args:
129129
source: Source email address
130130
to_addresses: List of recipient email addresses
131131
subject: Email subject
132-
body: Email body
132+
body: Email body which can be either basic str or MIMEText (which can allow html with hyperlinks)
133133
attachments_paths: List of optional paths to read contents from and attach to the email
134134
Returns: `SendEmailResponseTypeDef`
135135
"""
@@ -139,7 +139,10 @@ def send_email_with_attachment(
139139
msg["To"] = ", ".join(to_addresses)
140140

141141
msg_body = MIMEMultipart("alternative")
142-
msg_body.attach(MIMEText(body))
142+
if isinstance(body, str):
143+
msg_body.attach(MIMEText(body))
144+
else:
145+
msg_body.attach(body)
143146
msg.attach(msg_body)
144147

145148
if attachments_paths is not None:

0 commit comments

Comments
 (0)