Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

message.addHeader function not backwards compatible #30

Closed
dittmarconsulting opened this issue Sep 4, 2021 · 2 comments
Closed

message.addHeader function not backwards compatible #30

dittmarconsulting opened this issue Sep 4, 2021 · 2 comments

Comments

@dittmarconsulting
Copy link

dittmarconsulting commented Sep 4, 2021

Hi all,

A few months ago I changed the API to TLS and with that I refactored the code to use the version 1.5.6.

Everything was working fine with the (simplified) code below:

ApiClient client = PMApiClient.getApiClient();
String htmlBody = "<p>Hello world</a></p>";
Message message = new Message("<from email>", <to email>", "Hello from Postmark!", htmlBody);
message.addHeader("Powered by", "Bookmemate");
...

For a month (or even longer) all emails lost their formatting and all my clients received something like that

Powered by:Bookmemate
Feedback-ID: s1867426-_:s1867426:a109200:postmark
X-Complaints-To: abuse@postmarkapp.com
X-Job: 109200_1867426
X-PM-Message-Id: 07c82a3b-73e6-4373-9eba-a678fcec16d7
X-PM-RCPT: |bTF8MTA5MjAwfDE4Njc0MjZ8dGhvbWFzQGJvb2ttZW1hdGUuY29t|
X-PM-Message-Options: v1;9Hcc_PIAriBnYBOfaIwCcyIPcaJJ4QcTBG0Vjf0upsKfpR9qOJtFHrXwPywaBTAW0yivONdmCE8g_Gy1UcqUBBDOwW7mU_BYoMQKRhXnXR0
MIME-Version: 1.0
X-virtual-MTA: ord-104-245-209-198
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<p style=3D"font-family:Helvetica,Arial,sans-serif"><span style=3D"col=
or:#000">Dear Thomas Dittmar,</span></p><p style=3D"font-family:Helvet=
ica,Arial,sans-serif"><span style=3D"color:#000">Please find attached =
your Invoice.</span></p><p style=3D"font-family:Helvetica,Arial,sans-s=
erif"><span style=3D"color:#000">Sincerely,</span><br><span style=3D"c=
olor:#000">Smith Haircutters</span><br><span style=3D"color:#000">john=
@smith.com</span></p><img src=3D"https://ea.pstmrk.it/open/v3_ytvfB5yr=
Mc05cc23gp9WhZ-ZvRAqmnFzqi-eLw67F9KW9nQ7IqDFOFc4-6G25dmnjBWPFhCkbjZ7Z1=
XE8TiYC9adTorfeR3Oyh0LwuVeLxKymFDHGC4iU1ahz6nnnicM9nUQz6Z3lwTvPaPsZati=
oh9UZe55Rx8idp9YrymsVIBkmNMsEgXitD7djPI66Sv9ZbBq79X5XdPLfcAkPAOquargTr=
nr-0OaDhIcaa_zBTOXC5AHRZwY3cCJRDi7b626QRUjiDuUcvpoB95iQxo1GaP5cpeCwFze=
D_AWjgH2hMUmMNt6ziDVq7oQozcZ0aZ3wd7VFr_MW9h6fhIZXQRnjvVs81KqpFLVMctp_b=
4--SB_4cHb3vgLjulbtFpiHuuD0YSa7lia3W89oPhVv55cz5bXMk3hPXBVpBI1oxdL-SvJ=
sT962ztgAV85sW_z889Z" width=3D"1" height=3D"1" border=3D"0" alt=3D"" /=
>

It turns out that this line message.addHeader("Powered by", "Bookmemate"); caused that problem.

Because all emails were successfully sent I never received an error on my end and hence, nobody, apart from the end users that received the garbage, saw any issues.

This is unacceptable. If you change the API that drastically, please inform the users that pay for this service or at least raise an error so that it can be fixed.

The other thing is, why is this API not backwards compatible? Meaning, the old code and the new code should work in parallel.

Best regards,

Thomas
Director of Bookmemate

@RupW
Copy link

RupW commented Sep 4, 2021

Which version used to work? I've tried this with 1.1.7 and I see this behaviour too.

The problem is the space in your header name, which isn't allowed in header field names

A field name MUST be composed of printable US-ASCII characters (i.e., characters that have values between 33 and 126, inclusive), except colon.

so mail clients assume it isn't a header and treat it as the start of the mail body. Hence what you're seeing. Try something like

message.addHeader("X-Powered-By", "Bookmemate");

instead.

The only thing I can guess that might have changed in the library would be if custom headers used to go at the end of the default headers, so mail clients already thought they were processing headers not body and you got away with the space. But as I said even the very old version I'm using puts custom headers first, so I'm not sure that's it.

@dittmarconsulting
Copy link
Author

Sorry for the late reply.

That message.addHeader("Powered-by", "Bookmemate"); actually worked.

Thank you so much @RupW

PS: I will close this ticket but it would be great if you can update the docs and let others know, although it's been known that, for instance HTTP header don't allow spaces either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants