Steps 1 through 6 are working great. I run into a problem when trying to populate the TO field in the Outlook node. No matter how I format things, I keep getting an error related to string or an array.
I tried modifying my code in the email node to change the output:
const items = $input.all();
// Extracting the ResponsibleUserEmailAlias field and removing duplicates
const emailAddresses = Array.from(new Set(
items
.map(item => item.json.ResponsibleUserEmailAlias)
.filter(alias => typeof alias === “string” && alias.trim() !== “”) // Ensure alias is a non-empty string
.map(alias => ${alias}@email.com) // Append ‘@email.com’
));
// If you need to split a semicolon-delimited string (optional)
const emailString = emailAddresses.join("; “); // Join into a semicolon-delimited string first
const emailArray = emailString.split(”; "); // Split back into a flat array
// Return the flat array of email addresses wrapped in an object with ‘json’ key
return [{ json: {emailString} }];
I have tried returning the emailString, the emailAddresses, and the emailArray. All give me the same error.
If I simply put a fixed email in the TO field – it works.
I am not sure where you are saying to put that expression. I need the code in the email list node to iterate through the list that comes from the Format Data node. That node generates a table with headers that I am converting into a file to attach to the email. That list may have blanks in the field with the username as well as duplicates so I need to filter out both. Also, there isn’t an email - there is a username that I can add @XYZ.com to get a valid email. So, I am taking the full table from the output of Format Data, pulling the username from the one column, and using the code to generate the email addresses. That gets put into an array because I thought I needed that to put into the To: field.
I have tried simply using the expression you gave as the expression in the Outlook node’s To: field. I did this by commenting out the const emailString and const emailArray lines in the code and returned only emailAddresses. Then, I used the expression in the To field. I get the list of email like you showed, but still get the error.
Did I misunderstand where I should use the expression? Sorry if I did. I am still new to N8N - though I am really liking it so far (this little problem not withstanding).
I appreciate any direction that can help. Thanks!
Thanks! That gave me an idea. I should eliminate other variables. In my original flow, I was also pulling in a file as an attachment. If I remove that node from the flow - at least the connection to the outlook node - I can create the email.
As soon as I make that connection, it starts failing with that same error. I do not even have to add an attachment. It is just that connection to the node.
Based on the options in the Outlook node, I think I should be able to attach a file directly from the Convert to file node. Is that correct or am I missing a step?
TLDR; It works without an attachment node in the flow.
Hey @Jamie_C , do you intent to attach the file and send it out to the email addresses in the same email? Than your workflow cannot fulfill that as you are separating the file from the email list. This way you are attempting to send the email twice: one with attachment without the email address (hence the error you are getting) and the other email without the attachment (never happens as it fails the first time when attempting to send attachments).
For it to work, one of the option is for you to merge the two nodes first just before the Outlook node. Something like this.
Hey @Jamie_C , the way I showed in the workflow is the way to go provided both “Convert to File” and “email list” produce only one item. That is pick the the mode “Combine” and combine by “Position”. This will allow creating only 1 items with properties from both nodes.
There seems to be an issue with the page indeed. We would have to fix that. Thanks for pointing out to it.