Send Mail
Sends an email via Microsoft Exchange Server using Exchange Web Services (EWS). This node supports sending emails with HTML or plain text content, multiple recipients, and file attachments.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.
Input
- Exchange Web Service Url - The EWS endpoint URL (e.g.,
https://mail.company.com/EWS/Exchange.asmxorhttps://outlook.office365.com/EWS/Exchange.asmx). Required. - To - Recipient email addresses. For multiple recipients, separate with commas or semicolons (e.g.,
user1@company.com, user2@company.com). Required. - Cc - CC recipient email addresses. For multiple recipients, separate with commas or semicolons. Optional.
- Bcc - BCC recipient email addresses. For multiple recipients, separate with commas or semicolons. Optional.
- Subject - Email subject line. Optional (defaults to empty string).
- Body - Email body content. Can be plain text or HTML based on "Is Body HTML" option. Required.
- Attachments - Array of file paths to attach to the email (e.g.,
["C:\\Reports\\report.pdf", "C:\\Data\\data.xlsx"]). Optional.
Output
- n/a - No output. The email is sent but no data is returned.
Options
- Is Body HTML - If true, the body content will be sent as HTML. If false, body is sent as plain text. Default is false.
- Save Copy - If true, save a copy of the sent email to Sent Items folder. Default is false.
- Exchange Version - Exchange Server version for compatibility:
- Exchange2007_SP1 (default)
- Exchange2010
- Exchange2010_SP1
- Exchange2010_SP2
- Exchange2013
- Exchange2013_SP1
- Credentials - Exchange Server login credentials (username/password) from vault. Required.
- Ignore SSL Errors - If true, bypass SSL certificate validation. Use with caution, only for testing or trusted internal servers. Default is false.
How It Works
The Send Mail node:
- Validates all required inputs (URL, To, Body, Credentials)
- Connects to Exchange Server using provided credentials and EWS URL
- Creates an email message with specified subject and body
- Parses and adds To, Cc, and Bcc recipients (supports comma or semicolon separation)
- Attaches files if provided (validates file existence)
- Sets body type (HTML or plain text)
- Sends the email or saves to Sent Items based on "Save Copy" option
- Implements automatic retry logic for transient errors (3 attempts with exponential backoff)
The node uses TLS 1.2 for secure connections. File attachments must exist at the specified paths before sending. Empty or whitespace-only email addresses in recipient lists are automatically filtered out.
Examples
Send Simple Text Email
Send a basic plain text email to a single recipient:
// Send Mail node configuration
exchange_url = "https://mail.company.com/EWS/Exchange.asmx"
to = "recipient@company.com"
subject = "Automation Report"
body = "The automation has completed successfully. Please review the attached report."
// Options:
// Is Body HTML: false
// Save Copy: true
// Credentials: exchange_credentials (from vault)
// Email sent - no output
Send HTML Email with Formatting
Send a formatted HTML email:
// Send Mail node
exchange_url = "https://outlook.office365.com/EWS/Exchange.asmx"
to = "manager@company.com"
subject = "Weekly Sales Report"
body = `
<html>
<body>
<h1>Weekly Sales Report</h1>
<p>Dear Manager,</p>
<p>Here is the summary for this week:</p>
<ul>
<li><strong>Total Sales:</strong> $50,000</li>
<li><strong>New Customers:</strong> 25</li>
<li><strong>Conversion Rate:</strong> 15%</li>
</ul>
<p>Best regards,<br>Automation System</p>
</body>
</html>
`
// Options:
// Is Body HTML: true
// Save Copy: true
Send to Multiple Recipients with Attachments
Send email to multiple people with file attachments:
// Send Mail node
exchange_url = "https://mail.company.com/EWS/Exchange.asmx"
// Multiple recipients (comma-separated)
to = "team1@company.com, team2@company.com, team3@company.com"
cc = "manager@company.com"
bcc = "archive@company.com"
subject = "Monthly Report - January 2025"
body = "Please find attached the monthly report and data analysis."
// Attach multiple files
attachments = [
"C:\\Reports\\Monthly_Report_Jan2025.pdf",
"C:\\Data\\Sales_Data_Jan2025.xlsx",
"C:\\Charts\\Performance_Chart.png"
]
// Options:
// Save Copy: true
Dynamic Email Content
Create email content dynamically based on data:
// Prepare data
customer_name = "John Smith"
order_number = "ORD-12345"
total_amount = 299.99
order_date = new Date().toLocaleDateString()
// Send Mail node
exchange_url = "https://mail.company.com/EWS/Exchange.asmx"
to = "customer@example.com"
subject = `Order Confirmation - ${order_number}`
body = `
<html>
<body>
<h2>Thank you for your order!</h2>
<p>Dear ${customer_name},</p>
<p>Your order has been confirmed.</p>
<table border="1" cellpadding="5">
<tr>
<td><strong>Order Number:</strong></td>
<td>${order_number}</td>
</tr>
<tr>
<td><strong>Date:</strong></td>
<td>${order_date}</td>
</tr>
<tr>
<td><strong>Total Amount:</strong></td>
<td>$${total_amount}</td>
</tr>
</table>
<p>We'll notify you when your order ships.</p>
<p>Best regards,<br>Customer Service Team</p>
</body>
</html>
`
// Options:
// Is Body HTML: true
// Save Copy: true
Send Bulk Emails with Loop
Send personalized emails to multiple recipients:
// Load recipient list
recipients = [
{email: "user1@company.com", name: "Alice Johnson", dept: "Sales"},
{email: "user2@company.com", name: "Bob Williams", dept: "Marketing"},
{email: "user3@company.com", name: "Carol Davis", dept: "IT"}
]
// Loop through recipients
for (recipient of recipients) {
// Send Mail node
exchange_url = "https://mail.company.com/EWS/Exchange.asmx"
to = recipient.email
subject = "Department Update - " + recipient.dept
body = `
<html>
<body>
<p>Dear ${recipient.name},</p>
<p>This is an important update for the ${recipient.dept} department.</p>
<p>Please review the attached information at your earliest convenience.</p>
<p>Best regards,<br>Management</p>
</body>
</html>
`
// Options:
// Is Body HTML: true
// Save Copy: false
// Add delay to avoid throttling
await delay(2000) // 2 second delay between emails
}
Send Report with Generated Attachment
Generate a report file and email it:
// Generate report file
report_path = "C:\\Reports\\daily_report.pdf"
// ... code to generate PDF report ...
// Send Mail node
exchange_url = "https://mail.company.com/EWS/Exchange.asmx"
to = "reports@company.com"
cc = "manager@company.com"
subject = `Daily Report - ${new Date().toLocaleDateString()}`
body = "Please find attached today's automated report."
attachments = [report_path]
// Options:
// Is Body HTML: false
// Save Copy: true
Send Alert Email
Send urgent notification without attachment:
// Send Mail node
exchange_url = "https://mail.company.com/EWS/Exchange.asmx"
to = "alerts@company.com, oncall@company.com"
subject = "ALERT: System Error Detected"
body = `
<html>
<body style="color: red;">
<h1>⚠️ SYSTEM ALERT</h1>
<p><strong>Severity:</strong> HIGH</p>
<p><strong>Time:</strong> ${new Date().toLocaleString()}</p>
<p><strong>Message:</strong> Database connection failed. Immediate attention required.</p>
<p>Please investigate and resolve immediately.</p>
</body>
</html>
`
// Options:
// Is Body HTML: true
// Save Copy: true
Tips for Effective Use
- Recipient formats: Separate multiple recipients with commas or semicolons
- Email validation: Node validates email addresses and shows clear errors for invalid formats
- HTML formatting: Use HTML for rich formatting, tables, and styling
- Attachment paths: Use absolute file paths, verify files exist before sending
- Save copy: Enable "Save Copy" to keep sent emails in Sent Items for tracking
- Error handling: Use Try-Catch for robust email sending
- Retry logic: Node automatically retries on transient errors (3 attempts)
- Bulk sending: Add delays between emails to avoid server throttling
- SSL security: Only disable SSL validation for trusted internal servers
- Credentials: Store Exchange credentials securely in vault
- Testing: Test with a single recipient before sending bulk emails
Common Errors and Solutions
"ErrInvalidArg: Exchange Web Service Url cannot be empty"
Cause: No EWS URL was provided.
Solution: Provide the correct Exchange Web Services URL:
// For on-premises Exchange
exchange_url = "https://mail.company.com/EWS/Exchange.asmx"
// For Exchange Online
exchange_url = "https://outlook.office365.com/EWS/Exchange.asmx"
"ErrInvalidArg: To cannot be empty"
Cause: No recipient email address was specified.
Solution: Provide at least one recipient:
to = "recipient@company.com"
// Or multiple recipients
to = "user1@company.com, user2@company.com"
"ErrInvalidEmail: Invalid email address"
Cause: Email address format is invalid.
Solution: Ensure email addresses are properly formatted:
// Correct
to = "user@company.com"
// Incorrect
to = "invalid-email" // Missing @ and domain
"ErrFileNotFound: Attachment file does not exist"
Cause: Specified attachment file path doesn't exist.
Solution: Verify file exists before sending:
// Check file exists
attachment_path = "C:\\Reports\\report.pdf"
// Verify file exists first
if (require('fs').existsSync(attachment_path)) {
attachments = [attachment_path]
} else {
throw new Error("Report file not found")
}
"ErrInvalidArg: Body cannot be null"
Cause: Email body is null or undefined.
Solution: Provide body content (can be empty string):
body = "Email content here"
// Or empty if needed
body = ""
"ErrInvalidArg: No Credentials Content" or "Username/Password not found"
Cause: Credentials are missing or improperly configured.
Solution: Create proper credentials in vault:
// In vault, create credentials with:
{
"username": "user@company.com",
"password": "your_password"
}
// Then select these credentials in Credentials option
"ErrSendFailed: Failed to send email after 3 attempts"
Cause: Exchange server throttling, connection limits, or temporary network issues.
Solution:
- Wait a few moments and retry
- Check network connectivity to Exchange Server
- Verify Exchange Server is not experiencing issues
- For bulk sending, add delays between emails
- Check if sender has permission to send emails
"ErrAttachment: Failed to add attachment"
Cause: Issue attaching file (file too large, permissions, etc.).
Solution:
- Verify file size is within Exchange limits (typically 10-25 MB)
- Check file permissions are readable
- Ensure file is not locked by another process
- Verify file path is correct and absolute
"ErrConnection: Network error"
Cause: Network connectivity issues to Exchange Server.
Solution:
- Verify the EWS URL is accessible
- Check firewall settings
- Test connectivity using a browser
- Ensure DNS resolution works for the Exchange Server
"ErrExchangeService: Exchange service error (non-retriable)"
Cause: Exchange Server rejected the request (permissions, mailbox issues, etc.).
Solution:
- Verify sender account has permission to send emails
- Check mailbox is not over quota
- Ensure recipient addresses are valid
- Verify Exchange Server configuration allows sending
Best Practices
- Validate inputs: Check recipient addresses and file paths before sending
- Error handling: Implement Try-Catch blocks for robust automation
- Rate limiting: Add delays when sending bulk emails (2-5 seconds between sends)
- HTML testing: Test HTML emails to ensure proper rendering
- Attachment management: Verify files exist and are within size limits
- Save copies: Enable "Save Copy" for audit trails and record keeping
- Credentials security: Store credentials in vault, never hardcode
- Logging: Log sent emails for tracking and debugging
- Recipient validation: Validate email addresses before bulk sending
- Testing: Test with internal recipients before sending to external addresses
Email Automation Workflow
// 1. Prepare email data
recipient_email = "customer@example.com"
customer_name = "Jane Doe"
report_date = new Date().toLocaleDateString()
// 2. Generate or locate attachments
report_file = "C:\\Reports\\customer_report.pdf"
// ... generate report file ...
// 3. Create email body
subject = `Customer Report - ${report_date}`
body = `
<html>
<body>
<p>Dear ${customer_name},</p>
<p>Please find attached your requested report for ${report_date}.</p>
<p>If you have any questions, please don't hesitate to contact us.</p>
<p>Best regards,<br>Customer Service Team</p>
</body>
</html>
`
// 4. Send email with error handling
try {
// Send Mail node
exchange_url = "https://mail.company.com/EWS/Exchange.asmx"
to = recipient_email
subject = subject
body = body
attachments = [report_file]
// Options:
// Is Body HTML: true
// Save Copy: true
console.log(`Email sent successfully to ${recipient_email}`)
} catch (error) {
console.error(`Failed to send email: ${error.message}`)
// Handle error (retry, notify admin, etc.)
}
Related Operations
- Get Mail - Retrieve emails using Get Mail node
- Save Attachments - Download attachments with Save Attachments node
- Email Templates - Use programming nodes to create dynamic email templates
- File Processing - Generate reports and files before attaching to emails