Discourse SMTP "X-MSYS-API 'campaign_id' is limited to 64 bytes"

hmm…

when configuring SparkPost my emails were getting rejected by policy. with this error message:

“X-MSYS-API ‘campaign_id’ is limited to 64 bytes”

Is it possible that Discourse is generating a long campaign_id for my emails, as it never happened before but this time i used a long domain name of about 34 characters?

How can this be solved?

regards

i think line #94 in the file: discourse/app/controllers/webhooks_controller.rb :

  message_id = event["msys"]["message_event"]["campaign_id"] rescue nil

should be limited to 64 bytes!!! since sparkpost rejects longer campaign id’s!!

Or it can be solved from within line #143 at file : discourse/lib/email/sender.rb

@message.header['X-MSYS-API'] = { campaign_id: @message.message_id }.to_json

to avoid affecting other SMTP services…

Are we using this header @zogstrip?

Support for this header was added in this commit, and its use of the X-MSYS-API header is definitely broken according to the SparkPost docs. I’m thinking the code that sets that header just needs to be nuked from orbit. Any disagreements?

3 Likes

Is there any way i can fix it from production env?
as i just made a new install and cannot signup/login as admin or do anything else.

You could hand-edit the code in the container, which would persist until the next rebuild, but if you hang around for a little while, we’ll get it fixed properly, and you can just rebuild with the fixed code.

5 Likes

You could change “tests-passed” in app.yml to the id of a commit before the one that introduced the error. I made a post about that once, but can’t find it right now.

Oh,but if the database has migrated past you then that might not work.

1 Like

Thanks @mpalmer I will simply do that, and once a new update arrives will update it from the dashboard.

Just had this error myself - what should the line of code be changed/edited to/from?

Thanks for spotting it and bringing it up, @Yassine_Yousfi.

1 Like

change this line of code:

Or it can be solved from within line #143 at file : discourse/lib/email/sender.rb
@message.header[‘X-MSYS-API’] = { campaign_id: @message.message_id }.to_json

to this:

@message.header['X-MSYS-API'] = { campaign_id: @message.message_id[0..63] }.to_json

notice that i simply added the [0…63] keyword to cast the campaign id into 63 chars max. so it cannot be longer.

once u change that line, simply restart your discourse ./launcher restart app

and it should be working :slight_smile:

hope that helps.

3 Likes

Perfect!

Will keep this post in case the next update I do doesn’t have that commit in it. :thumbsup:

Can you take this fix @zogstrip?

1 Like

There’s actually no need to use that custom header since sparkpost already give us the message_id in the body :wink:

https://github.com/discourse/discourse/commit/3949c24f8004f0629c70e6555f3a0989e5b5df27

4 Likes

Amazing stuff - thanks @zogstrip, I can see it in the latest commits and I’m upgrading now!

This topic was automatically closed after 6 hours. New replies are no longer allowed.