Get Mail
Retrieves emails from Microsoft Exchange Server via Exchange Web Services (EWS). This node allows you to fetch emails from specific folders, filter by read status, and optionally mark messages as read.
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. - Mail Folder - Folder name to retrieve emails from (e.g., "Inbox", "Sent Items"). Default is "Inbox". Required.
- Number of Messages - Maximum number of emails to retrieve. Must be greater than zero. Default is 10. Required.
Output
- Result - List of Mail objects. Each mail object contains:
From- Sender email address (string)To- Array of recipient email addresses (string[])Cc- Array of CC recipient email addresses (string[])Subject- Email subject line (string)Body- Email body content as plain text (string)Id- Unique email identifier (string)DateTime- Email received date and time (DateTime)Attachments- Array of attachment objects, each containing:Name- Attachment filename (string)Id- Attachment identifier (string)
Options
- Only Unread Mails - If true, only retrieve unread emails. Default is false.
- Mark as Read - If true, mark retrieved emails as read. Default is false.
- Exchange Version - Exchange Server version for compatibility:
- Exchange2007_SP1
- Exchange2010
- Exchange2010_SP1
- Exchange2010_SP2
- Exchange2013
- Exchange2013_SP1 (default)
- Credentials - Exchange Server login credentials (username/password) from vault. Required.
How It Works
The Get Mail node:
- Connects to Exchange Server using provided credentials and EWS URL
- Locates the specified mail folder (case-insensitive for "Inbox")
- Retrieves up to the specified number of messages
- Filters by read status if "Only Unread Mails" is enabled
- Loads full email properties including sender, recipients, subject, body, and attachments
- Optionally marks emails as read if "Mark as Read" is enabled
- Returns list of mail objects with all metadata
- Implements automatic retry logic for transient errors (3 attempts with exponential backoff)
The node uses a 100-second timeout for Exchange operations and implements robust error handling for connection issues, server throttling, and temporary failures.
Examples
Retrieve Unread Inbox Emails
Get the 10 most recent unread emails from Inbox:
// Get Mail node configuration
exchange_url = "https://mail.company.com/EWS/Exchange.asmx"
mail_folder = "Inbox"
number_of_messages = 10
// Options:
// Only Unread Mails: true
// Mark as Read: false
// Credentials: exchange_credentials (from vault)
// Output: Result
emails = message.Result
// Process each email
for (email of emails) {
from = email.From
subject = email.Subject
body = email.Body
has_attachments = email.Attachments.length > 0
console.log(`From: ${from}, Subject: ${subject}`)
}
Monitor Specific Folder and Mark as Read
Retrieve emails from a custom folder and mark them as processed:
// Get Mail node
exchange_url = "https://outlook.office365.com/EWS/Exchange.asmx"
mail_folder = "Customer Requests"
number_of_messages = 50
// Options:
// Only Unread Mails: true
// Mark as Read: true
// Exchange Version: Exchange2013_SP1
emails = message.Result
// Process customer requests
for (email of emails) {
customer_email = email.From
request_body = email.Body
// Extract and process customer request
// Email is automatically marked as read
}
Extract Email Metadata
Get email details for processing and logging:
// Get Mail node
exchange_url = "https://mail.company.com/EWS/Exchange.asmx"
mail_folder = "Inbox"
number_of_messages = 20
emails = message.Result
// Create email log
email_log = []
for (email of emails) {
log_entry = {
id: email.Id,
from: email.From,
to: email.To.join(", "),
cc: email.Cc.join(", "),
subject: email.Subject,
received: email.DateTime,
attachment_count: email.Attachments.length,
attachment_names: email.Attachments.map(a => a.Name)
}
email_log.push(log_entry)
}
// Save to database or file
Filter Emails with Attachments
Process only emails that contain attachments:
// Get Mail node
exchange_url = "https://mail.company.com/EWS/Exchange.asmx"
mail_folder = "Inbox"
number_of_messages = 100
emails = message.Result
// Filter emails with attachments
emails_with_attachments = emails.filter(email =>
email.Attachments && email.Attachments.length > 0
)
for (email of emails_with_attachments) {
console.log(`Email from ${email.From} has ${email.Attachments.length} attachments`)
// Process each attachment
for (attachment of email.Attachments) {
console.log(`- ${attachment.Name}`)
}
}
Retrieve from Sent Items
Access sent emails for audit or archiving:
// Get Mail node
exchange_url = "https://mail.company.com/EWS/Exchange.asmx"
mail_folder = "Sent Items"
number_of_messages = 30
// Options:
// Only Unread Mails: false (get all sent items)
// Mark as Read: false
sent_emails = message.Result
// Archive sent emails
for (email of sent_emails) {
archive_record = {
to_recipients: email.To,
subject: email.Subject,
sent_date: email.DateTime,
body_preview: email.Body.substring(0, 100)
}
// Save to archive system
}
Tips for Effective Use
- Folder names: Use exact folder names as they appear in Outlook (case-sensitive except for "Inbox")
- Message limits: Start with smaller message counts (10-20) to avoid timeout issues
- Unread filtering: Use "Only Unread Mails" to process new emails efficiently
- Mark as read: Enable "Mark as Read" to prevent duplicate processing
- Error handling: Always use Try-Catch for robust automation
- Retry logic: The node automatically retries on transient errors (3 attempts)
- Email IDs: Save email IDs to track which messages have been processed
- Performance: Fetching large numbers of emails may take time; consider pagination
- Credentials: Store Exchange credentials securely in vault
- Exchange version: Match the version setting to your actual Exchange Server version
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: Mail Folder cannot be empty"
Cause: No folder name was specified.
Solution: Specify a valid folder name:
mail_folder = "Inbox" // or "Sent Items", "Drafts", etc.
"ErrFolderNotFound: Folder 'XYZ' not found"
Cause: The specified folder doesn't exist in the mailbox.
Solution:
- Verify the folder exists in Outlook
- Check spelling and capitalization (except for "Inbox")
- Use standard folders: "Inbox", "Sent Items", "Deleted Items", "Drafts"
"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
"ErrExchangeService: Failed to access folder"
Cause: Authentication failed or insufficient permissions.
Solution:
- Verify username and password are correct
- Ensure account has mailbox access permissions
- Check if account requires additional authentication (MFA)
- For Exchange Online, verify Basic Auth is enabled for EWS
"ErrTransientData: Failed to retrieve email after 3 attempts"
Cause: Exchange server throttling, connection limits, or temporary network issues.
Solution:
- Wait a few moments and retry
- Reduce the number of messages requested
- Check network connectivity to Exchange Server
- Verify Exchange Server is not experiencing issues
- For high-volume scenarios, add delays between requests
"ErrTimeout: Timeout error"
Cause: Exchange Server operation exceeded 100-second timeout.
Solution:
- Reduce the number of messages to retrieve
- Check Exchange Server performance
- Verify network latency to Exchange Server
- Try again during off-peak hours
"ErrConnection: Network error"
Cause: Network connectivity issues to Exchange Server.
Solution:
- Verify the EWS URL is accessible
- Check firewall settings
- Ensure DNS resolution works for the Exchange Server
- Test connectivity using a browser or ping
Best Practices
- Incremental processing: Process emails in batches rather than all at once
- Track processed emails: Store email IDs to avoid reprocessing
- Error handling: Implement Try-Catch blocks for robustness
- Credentials security: Store credentials in vault, never hardcode
- Folder organization: Use specific folders for different email types
- Message limits: Balance between efficiency and timeout risk
- Mark as read: Use strategically to track processing status
- Logging: Log email processing for audit trails
- Performance monitoring: Monitor execution times for large batches
- Version matching: Use correct Exchange version for best compatibility
Email Processing Workflow
// 1. Configure retrieval parameters
exchange_url = "https://mail.company.com/EWS/Exchange.asmx"
mail_folder = "Inbox"
batch_size = 20
// 2. Get unread emails
// Get Mail node
// Only Unread Mails: true
// Mark as Read: false
// Number of Messages: batch_size
emails = message.Result
// 3. Process each email
for (email of emails) {
try {
// Extract data
subject = email.Subject
from = email.From
body = email.Body
// Process based on subject or content
if (subject.includes("Invoice")) {
// Process invoice
processInvoice(email)
} else if (subject.includes("Request")) {
// Process request
processRequest(email)
}
// Mark as read after successful processing
// Or use a separate update operation
} catch (error) {
console.error(`Failed to process email ${email.Id}: ${error}`)
// Continue to next email
}
}
Related Operations
- Save Attachments - Use with Save Attachments node to download email attachments
- Send Mail - Reply to retrieved emails using Send Mail node
- Email Processing - Combine with programming nodes to extract data and trigger workflows
- Automation Triggers - Use with trigger nodes to monitor mailbox continuously