Skip to content

Commit a9d2879

Browse files
committed
raise type error when no recipients provided within i_email
1 parent 15e8014 commit a9d2879

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

emailer_lib/egress.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,53 +211,56 @@ def send_intermediate_email_with_mailgun(
211211
i_email=email
212212
)
213213
```
214-
214+
215215
Notes
216216
-----
217217
Requires the `mailgun` package: `pip install mailgun`
218218
"""
219219
from mailgun.client import Client
220-
220+
221221
# Create Mailgun client
222222
client = Client(auth=("api", api_key))
223-
223+
224+
if i_email.recipients is None:
225+
raise TypeError(
226+
"i_email must have a populated recipients attribute. Currently, i_email.recipients is None."
227+
)
228+
224229
# Prepare the basic email data
225230
data = {
226231
"from": sender,
227232
"to": i_email.recipients,
228233
"subject": i_email.subject,
229234
"html": i_email.html,
230235
}
231-
236+
232237
# Add text content if available
233238
if i_email.text:
234239
data["text"] = i_email.text
235-
240+
236241
# Prepare files for attachments
237242
files = []
238-
243+
239244
# Handle inline images (embedded in HTML with cid:)
240245
for image_name, image_base64 in i_email.inline_attachments.items():
241246
img_bytes = base64.b64decode(image_base64)
242247
# Use 'inline' for images referenced in HTML with cid:
243248
files.append(("inline", (image_name, img_bytes)))
244-
249+
245250
# Handle external attachments
246251
for filename in i_email.external_attachments:
247252
with open(filename, "rb") as f:
248253
file_data = f.read()
249-
254+
250255
# Extract just the filename (not full path) for the attachment name
251256
basename = os.path.basename(filename)
252257
files.append(("attachment", (basename, file_data)))
253-
258+
254259
# Send the message using Mailgun client
255260
response = client.messages.create(
256-
data=data,
257-
files=files if files else None,
258-
domain=domain
261+
data=data, files=files if files else None, domain=domain
259262
)
260-
263+
261264
return response
262265

263266

@@ -267,7 +270,7 @@ def send_intermediate_email_with_smtp(
267270
username: str,
268271
password: str,
269272
i_email: IntermediateEmail,
270-
security: str = Literal["tls", "ssl", "smtp"]
273+
security: str = Literal["tls", "ssl", "smtp"],
271274
):
272275
"""
273276
Send an Intermediate Email object via SMTP.

0 commit comments

Comments
 (0)