# Discourse SMTP "X-MSYS-API 'campaign\_id' is limited to 64 bytes"

**URL:** https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550
**Category:** Support
**Created:** [14 أكتوبر 2016، 2:26م UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550 "2016-10-14T14:26:30Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Yassine\_Yousfi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yassine_yousfi/32/195913_2.png) [@Yassine\_Yousfi](https://meta.discourse.org/u/Yassine_Yousfi)
#### Post date: [14 أكتوبر 2016، 2:26م UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/1 "2016-10-14T14:26:30Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Yassine\_Yousfi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yassine_yousfi/32/195913_2.png) [@Yassine\_Yousfi](https://meta.discourse.org/u/Yassine_Yousfi)
#### Post date: [14 أكتوبر 2016، 3:26م UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/2 "2016-10-14T15:26:52Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Yassine\_Yousfi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yassine_yousfi/32/195913_2.png) [@Yassine\_Yousfi](https://meta.discourse.org/u/Yassine_Yousfi)
#### Post date: [14 أكتوبر 2016، 3:34م UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/3 "2016-10-14T15:34:14Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [15 أكتوبر 2016، 4:44ص UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/4 "2016-10-15T04:44:42Z")

</div>

Are we using this header @zogstrip?

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [15 أكتوبر 2016، 4:56ص UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/5 "2016-10-15T04:56:02Z")

</div>

Support for this header was added in [this commit](https://github.com/discourse/discourse/commit/34af73c7cb6d6cd516f004f1e0e9e547d45d645c), and its use of the `X-MSYS-API` header is definitely broken according to [the SparkPost docs](https://developers.sparkpost.com/api/smtp-api.html). I’m thinking the code that sets that header just needs to be nuked from orbit. Any disagreements?

---

<div class="post-metadata">

### Author: ![Yassine\_Yousfi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yassine_yousfi/32/195913_2.png) [@Yassine\_Yousfi](https://meta.discourse.org/u/Yassine_Yousfi)
#### Post date: [15 أكتوبر 2016، 4:58ص UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/6 "2016-10-15T04:58:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [15 أكتوبر 2016، 5:01ص UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/7 "2016-10-15T05:01:17Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [15 أكتوبر 2016، 2:48م UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/9 "2016-10-15T14:48:45Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Yassine\_Yousfi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yassine_yousfi/32/195913_2.png) [@Yassine\_Yousfi](https://meta.discourse.org/u/Yassine_Yousfi)
#### Post date: [15 أكتوبر 2016، 5:26م UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/10 "2016-10-15T17:26:06Z")

</div>

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

---

<div class="post-metadata">

### Author: ![JamesNorth](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jamesnorth/32/283740_2.png) [@JamesNorth](https://meta.discourse.org/u/JamesNorth)
#### Post date: [17 أكتوبر 2016، 4:20ص UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/11 "2016-10-17T04:20:32Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Yassine\_Yousfi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yassine_yousfi/32/195913_2.png) [@Yassine\_Yousfi](https://meta.discourse.org/u/Yassine_Yousfi)
#### Post date: [17 أكتوبر 2016، 5:23ص UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/12 "2016-10-17T05:23:39Z")

</div>

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 🙂

hope that helps.

---

<div class="post-metadata">

### Author: ![JamesNorth](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jamesnorth/32/283740_2.png) [@JamesNorth](https://meta.discourse.org/u/JamesNorth)
#### Post date: [17 أكتوبر 2016، 5:29ص UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/13 "2016-10-17T05:29:16Z")

</div>

Perfect!

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

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [17 أكتوبر 2016، 6:05ص UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/14 "2016-10-17T06:05:23Z")

</div>

Can you take this fix @zogstrip?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [17 أكتوبر 2016، 9:27ص UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/15 "2016-10-17T09:27:30Z")

</div>

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

[https://github.com/discourse/discourse/commit/3949c24f8004f0629c70e6555f3a0989e5b5df27](https://github.com/discourse/discourse/commit/3949c24f8004f0629c70e6555f3a0989e5b5df27)

---

<div class="post-metadata">

### Author: ![JamesNorth](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jamesnorth/32/283740_2.png) [@JamesNorth](https://meta.discourse.org/u/JamesNorth)
#### Post date: [17 أكتوبر 2016، 12:21م UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/16 "2016-10-17T12:21:37Z")

</div>

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

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [17 أكتوبر 2016، 3:27م UTC](https://meta.discourse.org/t/discourse-smtp-x-msys-api-campaign-id-is-limited-to-64-bytes/51550/17 "2016-10-17T15:27:48Z")

</div>

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