Week 5 • Module 9

N/email Module

Sending programmatic emails with attachments and record linking

📧 Basic Email Sending

The N/email module provides email.send() for transactional emails from scripts:

const email = require('N/email');

email.send({
    author: 207,  // Employee internal ID
    recipients: 'customer@example.com',
    subject: 'Your Order Confirmation',
    body: 'Thank you for your order!'
});

Key Parameters

ParameterTypeDescription
authorNumberEmployee internal ID (sender)
recipientsString/ArrayEmail addresses or entity IDs (max 10)
subjectStringEmail subject line
bodyStringPlain text or HTML content
ccString/ArrayCC recipients (optional)
bccString/ArrayBCC recipients (optional)

⚠️ Recipient Limit

Maximum 10 recipients total across to, cc, and bcc fields. For bulk emails, use N/email.sendBulk() or a marketing platform.

📎 Attachments

Attach files from the File Cabinet:

const file = require('N/file');

const attachment = file.load({ id: 12345 });

email.send({
    author: 207,
    recipients: 'customer@example.com',
    subject: 'Your Report',
    body: 'Please find your report attached.',
    attachments: [attachment]
});

🔗 Linking to Records

Use relatedRecords to link emails to transactions for activity tracking:

email.send({
    author: 207,
    recipients: customerId,  // Can use entity internal ID
    subject: 'Order #' + orderNumber,
    body: emailBody,
    relatedRecords: {
        transactionId: salesOrderId,
        entityId: customerId
    }
});

✅ Activity Tracking

When you link an email to a record, it appears in the record's Communication subtab and Activity History, providing a complete audit trail.

🎨 HTML Emails

Send formatted HTML content:

const htmlBody = `
    <h1 style="color: #333;">Order Confirmation</h1>
    <p>Thank you for your order, ${customerName}!</p>
    <table>
        <tr><td>Order Number:</td><td>${orderNumber}</td></tr>
        <tr><td>Total:</td><td>${orderTotal}</td></tr>
    </table>
`;

email.send({
    author: 207,
    recipients: customerEmail,
    subject: 'Order Confirmation',
    body: htmlBody
});

📖 Finding This in the Docs

To look up N/email methods:

  1. Go to docs.oracle.com → SuiteScript 2.x Modules
  2. Click on N/email Module
  3. Review email.send() parameters and relatedRecords options

Key pages to bookmark:

🎯 Key Takeaways