ActiveCampaign / postmark-java

Official Java client library for the Postmark HTTP API
https://postmarkapp.com
MIT License
35 stars 21 forks source link

Allowing comma separated emails #32

Closed almothafar closed 3 years ago

almothafar commented 3 years ago

It seems this issue started to happen recently since the 8th of November, it seems that contains breaking changes for some reason, I was using Message and TemplateMessage and sending emails to multiple addresses with a comma-separated form like email1@company.com,email2@company.com.

Currently, it starts to fire exceptions in the log:

Caused by: com.wildbit.java.postmark.client.exception.InvalidMessageException: Error parsing 'To': Illegal email address 'email1@company.com,email2@company.com'. It must contain the '@' symbol.,
    at com.wildbit.java.postmark.client.HttpClientErrorHandler.throwErrorBasedOnStatusCode(HttpClientErrorHandler.java:37),
    at com.wildbit.java.postmark.client.HttpClientHandler.execute(HttpClientHandler.java:68),
    at com.wildbit.java.postmark.client.ApiClient.deliverMessageWithTemplate(ApiClient.java:167),
    at providers.emails.PostmarkEmailSenderServiceImp.sendMailWithTemplateTask(PostmarkEmailSenderServiceImp.java:170),
    at providers.emails.PostmarkEmailSenderServiceImp.lambda$sendMailWithTemplate$1(PostmarkEmailSenderServiceImp.java:69),
    at providers.emails.PostmarkEmailSenderServiceImp.lambda$sendMailScheduler$5(PostmarkEmailSenderServiceImp.java:112)

so, I wanted to fix that and I see there is a function called .setTo() that accepts an array or a map in Message and accepts Map only in TemplatedMessage which I don't understand and is confusing:

tomazy commented 3 years ago

@almothafar there haven't been any changes to the Postmark's API and it should l be working as expected - Postmark allows up to 50 recipients as comma separated list in a string: https://postmarkapp.com/developer/api/templates-api#email-with-template

It seems to me that there is something wrong with the string you're passing as the "To" field. It is not email1@company.com,email2@company.com but "email1@company.com,email2@company.com" (note the surrounding quotes) instead - could you check that?

You can also show us how you're constructing that message with multiple recipients.

almothafar commented 3 years ago

@tomazy I don't have any quotes around emails, also, I checked logs everything was working fine from 28th of Oct to 7th of Nov, we did 0 changes to the code, and we didn't do any deployment on the 7th of 8th of Nov. where the issue starts to happen, I did another deployment in 14th of Nov. but still having the same issue.

I have something like this:

String from = "noreply@mycompany.com";
String to = "email1@company.com,email2@company.com";
Integer templateId = 123;
String subject = "Test subject";

final TemplatedMessage templatedMessage = new TemplatedMessage(from, to, templateId);
templatedMessage.setReplyTo(from);
templatedMessage.setTemplateModel(Json.toJson(templateData));
client.deliverMessageWithTemplate(templatedMessage);
almothafar commented 3 years ago

OK, finally I saw the issue, To was "Name" <email1@company.com,email2@company.com> when I debugged it inside the postmark code itself, I found the reason for this, but I'm still confused, it was working like that before and now not working, or the change that deployed in 14th Nov. that written in 11th of Nov. somehow deployed to production in 7th to 8th of Nov., is that myself traveled in the time? or again that "Name" <email1@company.com,email2@company.com> was working and now not.

I'm totally confused...

Anyway, I fixed this from my side.

almothafar commented 3 years ago

And still, if you can see my other notes in bullets will be nice, I can open another issue of these bullets if you want.

tomazy commented 3 years ago

@almothafar glad you were able to locate and fix the problem. I'm going to close this ticket and please open separate ticket for other issues you have with the library.