Send Email (Text Field Not Working)

Hi,
I tried sending a mail with SMTP and it worked, but when we enter an expression in text field and execute the node, it shows the rendered text in result but when I check mail there is no mail text (body) present. this also happens when I add expression to the Subject. So only plain constant text is working and not expressions for send email node. Let me know if its a bug or should something else can be done.
Thanks

Hey @Asit_Joshi!

Would you be able to post a copy of the workflow that is causing you challenges? Seeing the exact parameters and settings of each node really helps in troubleshooting. Just make sure that you are removing any of your confidential information from the text before you post it publically.

1 Like

Hi @Tephlon

Here is my workflow . It checks for a particular field in sheet (which will contain ID, Subject, Mail Body, Status of Mail) and if its there, then it will pass the row details. Then it will get all contacts from Hubspot and send all of them mail via SMTP with the Body & Subject given in the sheet.

{
  "name": "Send Mail (Get Contact from HubSpot)",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        280,
        130
      ]
    },
    {
      "parameters": {
        "operation": "lookup",
        "sheetId": "",
        "range": "A:Z",
        "lookupColumn": "Status",
        "lookupValue": "ToSend",
        "options": {
          "returnAllMatches": true
        }
      },
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        540,
        440
      ],
      "credentials": {
        "googleApi": "Google API"
      }
    },
    {
      "parameters": {
        "operation": "update",
        "sheetId": "",
        "range": "A:Z",
        "key": "ID",
        "options": {}
      },
      "name": "Google Sheets1",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1360,
        440
      ],
      "credentials": {
        "googleApi": "Google API"
      }
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "Status",
              "value": "Successfully Sent"
            },
            {
              "name": "ID",
              "value": "={{$node[\"Google Sheets\"].json[\"ID\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1160,
        440
      ]
    },
    {
      "parameters": {
        "resource": "contact",
        "operation": "getAll",
        "returnAll": true,
        "additionalFields": {}
      },
      "name": "Hubspot1",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 1,
      "position": [
        760,
        440
      ],
      "credentials": {
        "hubspotApi": ""
      }
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "={{$node[\"Hubspot1\"].json[\"identity-profiles\"][0][\"identities\"][0][\"value\"]}}",
        "subject": "={{$node[\"Google Sheets\"].json[\"Subject\"]}}",
        "text": "={{$node[\"Google Sheets\"].json[\"Mail Body\"]}}",
        "options": {
          "allowUnauthorizedCerts": true
        }
      },
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        950,
        440
      ],
      "credentials": {
        "smtp": ""
      }
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "everyX",
              "value": 1,
              "unit": "minutes"
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        320,
        430
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        []
      ]
    },
    "Google Sheets": {
      "main": [
        [
          {
            "node": "Hubspot1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hubspot1": {
      "main": [
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cron": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": "3"
}

Im just getting error in the SMTP Mail sending where, I am not able to get Mail as it should when Subject & Body Text are set as Expression.

Thanks

Hey @Asit_Joshi. Thanks for uploading the workflow. This give a lot of context to your issue.

Can you confirm that the information that you are referencing is coming through to the Send Mail node? I’m wondering if the information is not getting passed properly to this node.

The other item to check is whether or not your mail client is not rendering the text portion of the email and is only rendering the HTML portion of the email. Could you attempt to duplicate the information that you are putting into the text:


That will tell us if the email client is causing issues.

Let us know your results.

Hi @Tephlon

I copied the same expression and pasted in HTML Field but no success.


As you can see in following images the expression is being send to this node but for some reason its sending blank mails and not passing the expression while sending mail.

Is there any problem with mail server ? cause when I try with plain text without expression it works perfectly fine.

Hey @Asit_Joshi,

It is possible that the mail server that you are using does not support one of these options but the odds of them not supporting both of these options is pretty much zero.

I don’t think the issue is with the mail server since it is getting the text when you do it without using an expression.

Try this…run your workflow and wait for the email to come through and confirm that the body is empty. Then, open up the send mail node and look to see what it gives you when you open up the expression editor. My gut tells me that the value will be blank.

1 Like

Hi @Tephlon

I tried that and when I ran workflow and opened the expression it shows the text that I had added earlier in the sheet, but the body and subject of the mail I received is still empty. I also tried changing the mail ID and using a different SMTP server but its also creating the same error.

As I was putting together the next troubleshooting task for you, I think I stumbled upon the problem!

The Send Email node is looking for fill in the Subject and Body fields with {{$node["Google Sheets"].json["Subject"]}} and {{$node["Google Sheets"].json["Mail Body"]}} fields. But, the value that is entered into those fields is their value at the moment they are referenced.

So, if the Google Sheets node has moved on to the next set of data to process by time the Send Email node is asking for the Subject and Mail Body values, the information that the Send Email node receives is not what it expects.

My recommendation would be to reference not the information from the specific node but to rather pass the information along in the workflow and then reference the information as an input to the node itself. My general rule is to try as much as I can to reference the node that came just before the node I am programming.

Let me know if that has helped at all.

Yes, I also think the data is lost somewhere, but Ive kept Cron to every 1 minute and the execution time in total is about 6 sec so its very low chance that it will take the blank value. If I Open the Execution History then you can see in the photo below that the values are set but looks like only the first mail (demo contact of hubspot) got the message not the others (as per message length).

It does look like the first one does have more information.

One thing to keep in mind is that each node will not necessarily wait for a full iteration of the workflow before it goes on to the next item on its list. It may run through a number of items for each iteration.

For example, the IMAP Email node will update its data for every unread email in the IMAP mailbox each time the workflow is executed and will pass information on to the next node once for each unread email. So, if there are two unread email in the mailbox, the node will pass along two sets of data on that single execution instance. If a node later down the line is executing on the first set of data but a referenced earlier node is already on the second set of data, that node may be presenting the wrong info.

Thanks @Tephlon

got a bit of idea of how iteration works in the node. So for this to keep the first data stored what should be done ? I tried with the set node but no success.

When at all possible, reference the node immediately before the node you are working in. So, for your workflow, your expressions in the Send Email node should reference the Hubspot1 node.

Can you share the example workflow of how it can be done cause the Hubspot1 Node does not consist the Subject and MailBody Fields. How we can add into it ?

@Asit_Joshi why do you want all the contacts? should not be just the contacts the Google Sheets node returned?

@RicardoE105
So my workflow is like I want to get contacts of a particular list (currently that is not available in the node) so I am using Get All Contacts and I want to send all contacts a Email from a Custom SMTP Server. So whenever I fill the details of a mail in the google sheet and make the status field as ToSend then it should send mail to the contacts (of the selected list).

@Asit_Joshi @Tephlon ahhh found the issue. The Email node was one of the first nodes thus it does not implement execute but executeSingle meaning it does not iterate for each element of the input. Will fix this.

1 Like

Ok, this is not the issue, I misunderstood how executeSingle works. Either way, I was able to do it without issues. Check the example below:

{
  "nodes": [
    {
      "parameters": {
        "operation": "lookup",
        "sheetId": "14ZJZBWmOWOFr9NldppEHnACOTReECG3olxG7VgLInHI",
        "range": "A:D",
        "lookupColumn": "status",
        "lookupValue": "toSent",
        "options": {
          "returnAllMatches": true
        }
      },
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        970,
        300
      ],
      "credentials": {
        "googleApi": "asas"
      }
    },
    {
      "parameters": {
        "operation": "update",
        "sheetId": "14ZJZBWmOWOFr9NldppEHnACOTReECG3olxG7VgLInHI",
        "range": "A:D",
        "key": "contactId",
        "options": {}
      },
      "name": "Google Sheets1",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1920,
        150
      ],
      "credentials": {
        "googleApi": "asas"
      }
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "[email protected]",
        "subject": "=sasasasasa",
        "text": "=asasasasas",
        "options": {
          "allowUnauthorizedCerts": true
        }
      },
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        1210,
        410
      ],
      "credentials": {
        "smtp": "asasasas"
      }
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "everyX",
              "value": 1,
              "unit": "minutes"
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        720,
        300
      ]
    },
    {
      "parameters": {
        "mode": "mergeByKey",
        "propertyName1": "email",
        "propertyName2": "envelope.to"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1450,
        150
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "status",
              "value": "sent"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1680,
        150
      ]
    }
  ],
  "connections": {
    "Google Sheets": {
      "main": [
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Cron": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Hey @RicardoE105 @Tephlon
Got the solution for this. Just interchanged the HubSpot Node with Google Sheets node so the Hubspot Node Runs First and then runs the Google sheet node with the number of contacts in the hubspot output. This gives data for each contact in the email node.

4 Likes

Well done, @Asit_Joshi!
Thanks for not giving up and for sharing your solution!

2 Likes