# Node-red-node-email headers format

**URL:** <https://discourse.nodered.org/t/node-red-node-email-headers-format/86383>\
**Category:** General\
**Created:** [12 March 2024 22:26 UTC](https://discourse.nodered.org/t/node-red-node-email-headers-format/86383 "2024-03-12T22:26:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![clmcavaney](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/clmcavaney/32/89241_2.png) [@clmcavaney](https://discourse.nodered.org/u/clmcavaney)\
**Post date:** [12 March 2024 22:26 UTC](https://discourse.nodered.org/t/node-red-node-email-headers-format/86383/1 "2024-03-12T22:26:29Z")

</div>

G'day,  
I was wanting to add a header in an email sent via the [node-red-node-email node](https://flows.nodered.org/node/node-red-node-email) but I am having trouble with the format of the headers element.

I have tried both a simple string `"X-header-name: value"` and a JSON object `{"X-header-name": "value"}` but they are not coming through with the email.

Is there some other format that the underlying [nodemailer](https://www.npmjs.com/package/nodemailer) library is requiring?

Thanks for any input on this.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 March 2024 22:46 UTC](https://discourse.nodered.org/t/node-red-node-email-headers-format/86383/2 "2024-03-12T22:46:58Z")

</div>

Reading the help text the `"X-header-name"` should be sent in msg.headers  
eg  
in a change node  
set `msg.` `headers["X-header-name"]`  
to value string `value`

In a function node

```auto
msg.headers = {};
msg.headers["X-header-name"] = "value";
return msg;

```

---

<div class="post-metadata">

**Author:** ![clmcavaney](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/clmcavaney/32/89241_2.png) [@clmcavaney](https://discourse.nodered.org/u/clmcavaney)\
**Post date:** [13 March 2024 22:32 UTC](https://discourse.nodered.org/t/node-red-node-email-headers-format/86383/3 "2024-03-13T22:32:21Z")

</div>

> [@E1cid](#):
>
> ```auto
> msg.headers = {};
> msg.headers["X-header-name"] = "value";
> 
> ```

Thanks @E1cid  
I tried a setting the header in that way in an `inject` node and also in a `function` node.  
Both present like this in a debug:

```auto
headers: object
    X-header-name: "value"

```

But the header is **not** included in the email received.

Quite strange.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [13 March 2024 22:43 UTC](https://discourse.nodered.org/t/node-red-node-email-headers-format/86383/4 "2024-03-13T22:43:27Z")

</div>

Could you try something:

1. Edit your email node & remove the email address.
2. In your function, set `msg.to = "the_email@address"` (where the\_email@address is the email removed from step 1)

I don't know why but it seems headers won't be sent if the to field is set: [node-red-nodes/social/email/61-email.js at ea48b6acdd469d8c790503459c3f96994e3eab9b · node-red/node-red-nodes · GitHub](https://github.com/node-red/node-red-nodes/blob/ea48b6acdd469d8c790503459c3f96994e3eab9b/social/email/61-email.js#L115)

@dceejay any thoughts on this ^?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 March 2024 22:59 UTC](https://discourse.nodered.org/t/node-red-node-email-headers-format/86383/5 "2024-03-13T22:59:58Z")

</div>

TBH. No idea. Must have been a reason back in the mists of time…. But can’t recall now.

---

<div class="post-metadata">

**Author:** ![clmcavaney](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/clmcavaney/32/89241_2.png) [@clmcavaney](https://discourse.nodered.org/u/clmcavaney)\
**Post date:** [17 March 2024 03:56 UTC](https://discourse.nodered.org/t/node-red-node-email-headers-format/86383/6 "2024-03-17T03:56:34Z")

</div>

G'day Steve,

Thanks for the suggestion.  
That works.

Regards,  
Christopher

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [15 June 2024 03:57 UTC](https://discourse.nodered.org/t/node-red-node-email-headers-format/86383/7 "2024-06-15T03:57:03Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
