Msg.atachments with msg.payload input

Hi, I've been reading some threads in the forum but I cannot find a way to use msg/payload values inside attachments filename and content... I'm using as reference some threads from forum, and nodemailer info.

I'm trying to use payload contents to define atachment name and content, this is part if the payload arriving to function node that is injected into email node:
image

If I try with other payload parts in the filename, it works... for example with _msgid value... but when I try to a value inside the [0] it doesnt:

msg.attachments = [
    {
        filename: msg.payload.adjunto[0].adjunto,
        content: msg.payload.buffer
    }

];

return msg;

Regarding the filename, this is the error:
image
I guess there is other way to call that value inside function but I cannot manage to find :frowning:
And regarding the content, maybe is not so simple to call the buffer coming from payload? It seems to come in "raw" format
image

Thanks!

That error implies that msg.payload.adjunto does not exist on the received msg. You could add a node.warn statement at the start of your function node to output msg.payload.adjunto to make sure.

How can I do that?
In any case why there would not be there? this is the debug of msg.payload of the node injecting into email node:
image

If I use in filename something like msg._msgid... it works, and uses for file name that 2e97...etc, but when I use other deeper data as I tried above it doesn work. Is there any different way to call arrays of objects in a function?

Add `node.warn(msg.payload.adjunto) to the top of the function node and see if you get an error from that line and check the output in the debug side panel (or the node-red log if you prefer).

No idea, but the error is clear. Whenever I've had issues like that in the past, it was either because I mistyped the property name or I got a message that didn't actually have the data I thought it did.

Not really but then it isn't actually the array part that you are getting an error for, it is the property name itself. It doesn't think that property exists (undefined) so it can't give you the first element. Which is why I suggest putting in an extra statement to check.

Thought of one other possibility, that the property you think is named adjunto might have a non-printable character on it - or maybe has an extended character - somthing that isn't getting printed but that exists anyway? Still, the warn output is the first check.

You're right about that variables... I don;t know why but even appearing on the debug they were not really arriving to function node (nothing inside payload), only the objects in the root, so I managed to change its value to something different than inside payload before join node:
image

And now, the function node that is after the join node received this ok. I did same with buffer, changing payload to msg.buffer... and now both are fine used by function node.
I will try to see why this was happening... but at least it works, thanks @TotallyInformation :wink:

Just for anyone else to now that it works as it was intended to:), i leave here function node for mail attachment now without the payload related ones that I'm using now:


msg.topic = msg.subject;
msg.payload = msg.cuerpo;

msg.attachments = [
    {
        filename: msg.nombrearchivo,
        content: msg.buffer
    }
];

return msg;

image

Does that come from a debug node set to Output Complete Message?
If so then there is something odd about the message it is getting. Note that it says
buffer: msg: Object

The buffer bit should not be there. Where is that message coming from?
Also are you sure that debug is showing the message going into your Change node?

Hi, yes it was with Output Complete Message because I needed to debug the buffer somehow, that they was I was getting the file to later be attached in the email.

This is coming from a Join node, that gets 3 things: email body and subject, attachment name, and attachment content (in buffer it seems, thats all i get). Then after this Join node it goes to the Function node i showed above... and then to email node.

The thing is that the debug node i was using was showing some payload info that... was not really there, I dont know why. I may have a poltergeist with several stuff via Join nodes... it works... but I still dont know why it wasnt the other way :(...

So, interesting to note that
image
is not what you had in your function node: msg.payload.adjunto[0].

Show us the output of debug nodes set to show complete message showing what is going into the join node and what is coming out.

yeah, maybe because all the changes, but i was using variable name exactly as it came in. Maybe a lot of copy&paste here lead to typo/error, thanks for nticing anyway

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