# Email node sending as attachment instead of html

**URL:** <https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058>\
**Category:** General\
**Created:** [22 January 2023 16:09 UTC](https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058 "2023-01-22T16:09:28Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![pepeday](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pepeday/32/73881_2.png) [@pepeday](https://discourse.nodered.org/u/pepeday)\
**Post date:** [22 January 2023 16:09 UTC](https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058/1 "2023-01-22T16:09:28Z")

</div>

So I've noticed some strange behaviour which I can't pinpoint why is happening.  
I am using an email node to send emails. My payload is html content.

When I specify the "to" field in the email node itself, the email is sent correctly.

If I specify msg.to in any previous node (and clear the "to" field in the email node), then all of the content of the email shows up as an attachment and the email body is completely empty.

Any idea what could be going on?

Thanks,  
P

---

<div class="post-metadata">

**Author:** ![softy2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/softy2k/32/23707_2.png) [@softy2k](https://discourse.nodered.org/u/softy2k)\
**Post date:** [22 January 2023 17:04 UTC](https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058/2 "2023-01-22T17:04:45Z")

</div>

Try : **msg.to** = ["youraddress@.email.com"]

You can set multiple recipients

---

<div class="post-metadata">

**Author:** ![pepeday](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pepeday/32/73881_2.png) [@pepeday](https://discourse.nodered.org/u/pepeday)\
**Post date:** [22 January 2023 17:27 UTC](https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058/3 "2023-01-22T17:27:33Z")

</div>

I've tried that with a function node just now. Array works in defining multiple addresses. However, the email body is still sent as an attachment instead of an actual html email.

---

<div class="post-metadata">

**Author:** ![softy2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/softy2k/32/23707_2.png) [@softy2k](https://discourse.nodered.org/u/softy2k)\
**Post date:** [22 January 2023 17:45 UTC](https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058/4 "2023-01-22T17:45:13Z")

</div>

Try this, in function node (just before email node)

```auto
msg.payload = "Email Body";
msg.to = ["youraddress@.email.com"];
msg.topic = "Topic Msg";
msg.attachments = [];

```

---

<div class="post-metadata">

**Author:** ![pepeday](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pepeday/32/73881_2.png) [@pepeday](https://discourse.nodered.org/u/pepeday)\
**Post date:** [22 January 2023 18:09 UTC](https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058/5 "2023-01-22T18:09:27Z")

</div>

A minimal example works but it doesn't work in my flow. It's odd. I'll try shifting around stuff to see that happens.

---

<div class="post-metadata">

**Author:** ![softy2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/softy2k/32/23707_2.png) [@softy2k](https://discourse.nodered.org/u/softy2k)\
**Post date:** [22 January 2023 18:10 UTC](https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058/6 "2023-01-22T18:10:13Z")

</div>

Versions of NodeRed, email Node, NodeJs ?

---

<div class="post-metadata">

**Author:** ![pepeday](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pepeday/32/73881_2.png) [@pepeday](https://discourse.nodered.org/u/pepeday)\
**Post date:** [22 January 2023 18:15 UTC](https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058/7 "2023-01-22T18:15:33Z")

</div>

node-red: 3.0.2  
email node: 1.18.4

Not sure how to get node.js version, literally just installed NR a few days ago, sorry!

---

<div class="post-metadata">

**Author:** ![softy2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/softy2k/32/23707_2.png) [@softy2k](https://discourse.nodered.org/u/softy2k)\
**Post date:** [22 January 2023 18:22 UTC](https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058/8 "2023-01-22T18:22:18Z")

</div>

In console, type : `node -v`

I use 16.19.0 (I don't changed to version 18)

---

<div class="post-metadata">

**Author:** ![pepeday](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pepeday/32/73881_2.png) [@pepeday](https://discourse.nodered.org/u/pepeday)\
**Post date:** [22 January 2023 18:31 UTC](https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058/9 "2023-01-22T18:31:15Z")

</div>

Mine would be 16.16.0

I just figured out that if I clear out the msg. content and then create the array, the email node works. So some parameter is messing up my node. I'll come back in a bit and report.

---

<div class="post-metadata">

**Author:** ![softy2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/softy2k/32/23707_2.png) [@softy2k](https://discourse.nodered.org/u/softy2k)\
**Post date:** [22 January 2023 18:34 UTC](https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058/10 "2023-01-22T18:34:04Z")

</div>

Take a look here : [Attachments :: Nodemailer](https://nodemailer.com/message/attachments/)

---

<div class="post-metadata">

**Author:** ![pepeday](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pepeday/32/73881_2.png) [@pepeday](https://discourse.nodered.org/u/pepeday)\
**Post date:** [22 January 2023 18:39 UTC](https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058/11 "2023-01-22T18:39:07Z")

</div>

So I think the problem might have been caused by a msg.headers which was carried over by an http request node. I am not sure.

The problem is anyhow resolved by clearing the msg variable and rebuilding it in the function node.

Thanks for your help, hopefull I will learn what exactly caused it and not repeat it again!

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 January 2023 20:41 UTC](https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058/12 "2023-01-22T20:41:34Z")

</div>

> [@pepeday](#):
>
> So I think the problem might have been caused by a msg.headers which was carried over

You could try using a change node and delete that element from the msg

---

<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:** [23 March 2023 20:41 UTC](https://discourse.nodered.org/t/email-node-sending-as-attachment-instead-of-html/74058/13 "2023-03-23T20:41:43Z")

</div>

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