themartorana / python-postmark

Postmark library for Python 2.6 and greater
http://davemartorana.com
MIT License
199 stars 83 forks source link

Problem sending batch with templates #86

Closed limewareio closed 4 years ago

limewareio commented 4 years ago

I tried sending batch with templates but it doesn't seem to work. If I send it without templates it works as intended.

While browsing through the code I found that 'email/batch' is hard-coded.

image

I looked at Postmarks API documentation https://postmarkapp.com/developer/api/templates-api#send-batch-with-templates and found that there's a different call for sending batch with templates. I don't know if it has worked before or if they recently made some changes to the endpoints.

Perhaps a solution to the problem could be to pass a flag indicating that you want to send batch with templates and change the 'email/batch' string depending on the value of that flag.

nicholasserra commented 4 years ago

Sounds right, thanks for the report! Can you toss me some steps to reproduce the issue? Just your commands would be fine. I'll take a look as soon as I can.

limewareio commented 4 years ago

Sure! You can try something like the code below to reproduce the issue.

from postmark.core import PMBatchMail, PMMail

SOME_TEMPLATE_ID = 12345678

def send_batch_mail():
    recipients = ['john.smith@example.com', 'jane.smith@example.com']
    template_model = {'url': 'https://www.example.com'}
    batch_mail = PMBatchMail()
    for recipient in recipients:
        message = PMMail(
            to=recipient,
            sender='noreply@example.com',
            template_id=SOME_TEMPLATE_ID,
            template_model=template_model,
        )
        batch_mail.add_message(message)
    batch_mail.send()