Open gregsadetsky opened 2 years ago
Thanks @gregsadetsky that was exactly what I was searching for.
I was passing something like this:
recipients = ["user1@example.com", "user2@example.com"]
subject = "test batch email"
tag = "test-tag"
emails = []
for to in recipients:
emails.append(
{
'To': to,
'From': 'from@example.com',
'ReplyTo': 'reply-to@example.com',
'Subject': subject,
'Tag': tag,
'MessageStream': 'broadcast',
'HtmlBody': html_body,
'TextBody': text_body,
}
)
postmark.emails.send_batch(emails)
Which my read of the docs implies should work?:
postmark.emails.send_batch(
{
'From': 'sender@example.com',
'To': 'receiver@example.com',
'Subject': 'Postmark test',
'HtmlBody': '<html><body><strong>Hello</strong> dear Postmark user.</body></html>',
},
{
'From': 'sender2@example.com',
'To': 'receiver2@example.com',
'Subject': 'Postmark test 2',
'HtmlBody': '<html><body><strong>Hello</strong> dear Postmark user.</body></html>',
}
)
Yet my code was throwing a ValueError
; switching to postmark.emails.send_batch(*emails)
as per your suggestion @gregsadetsky works fine though - thanks for getting me out of a hole!
The documentation for
send_batch
andsend_template_batch
both mention:However,
emails
is actually equivalent to*args
, i.e.emails
internally captures (withinsend_batch
andsend_template_batch
) all arguments passed to the function. The variable nameemails
is not actually exposed to the caller, and so isn't properly a "parameter".Calling:
will not work -- the function will instead confusingly return an empty array.
Just in case anybody comes here to troubleshoot this, the correct way to call the functon is rather:
Thanks!