Overview
This n8n custom node, named "Nodemailer2", enables sending emails via Gmail using OAuth2 authentication. It leverages the nodemailer and googleapis libraries to authenticate with Gmail and send messages. This node is useful for automating email notifications, alerts, or any workflow that requires sending emails from a Gmail account within an n8n workflow.
Common scenarios:
- Sending automated status updates or reports.
- Notifying users of workflow events (e.g., errors, completions).
- Relaying form submissions or contact requests via email.
Practical example:
You could use this node to send a daily summary email to your team, triggered by a scheduled workflow in n8n.
Properties
| Name | Meaning |
|---|---|
| The Gmail address used as the sender (must match the authenticated user). | |
| CLIENT_ID | OAuth2 client ID for Google API access. |
| CLIENT_SECRET | OAuth2 client secret for Google API access. |
| RERIRECT_URI | OAuth2 redirect URI registered in your Google Cloud project. |
| REFERSH_TOKEN | OAuth2 refresh token for obtaining new access tokens. |
| To | Recipient email address(es), comma-separated if multiple. |
| CC | CC recipient email address(es), comma-separated if multiple. |
| Subject | Subject line of the email. |
| Message | HTML content of the email body. |
Output
The node outputs a JSON object for each input item processed, with the following structure:
{
"to1": "<recipient(s) specified in 'To'>",
"cc": "<CC recipient(s)>",
"subject": "<email subject>",
"message": "<HTML message body>",
"data": {
// nodemailer response object, e.g.:
"accepted": ["<recipient@example.com>"],
"rejected": [],
"envelopeTime": 123,
"messageTime": 456,
"messageId": "<unique-message-id@domain>",
...
}
}
- The
datafield contains the full response from Nodemailer, which includes delivery status and metadata.
Dependencies
- External Services: Requires a Gmail account and a Google Cloud project with OAuth2 credentials (Client ID, Client Secret, Redirect URI, Refresh Token).
- API Keys / Credentials: You must provide valid OAuth2 credentials and a refresh token for the Gmail account.
- n8n Configuration: No special configuration required beyond providing the above credentials as node parameters.
Troubleshooting
Common issues:
- Invalid Credentials: If any OAuth2 parameter is incorrect, authentication will fail, and the node will throw an error.
- Access Denied: If the Gmail account does not have the correct permissions or the refresh token is invalid/expired.
- Email Delivery Issues: If recipient addresses are invalid or blocked, the
data.rejectedarray will contain those addresses.
Error handling:
- If "Continue On Fail" is enabled, failed items will be output with an
errorfield containing the error details. - Otherwise, the node will stop execution and throw an error, often including context such as the item index.