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

(sin) #1


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?


(sin) #2

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!!

(sin) #3

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…

(Jeff Atwood) #4

Are we using this header @zogstrip?

(Matt Palmer) #5

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?

(sin) #6

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.

(Matt Palmer) #7

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.

(Jay Pfaffman) #9

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.

(sin) #10

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

(James North) #11

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.

(sin) #12

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.

(James North) #13


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

(Jeff Atwood) #14

Can you take this fix @zogstrip?

(Régis Hanol) #15

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

(James North) #16

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

(Régis Hanol) #17

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