The N/email module enables SuiteScript developers to send relevant and creative email messages.

In this blog, let’s return to some additional SuiteScript modules that can help us in our NetSuite development projects.

Sending Emails with “email.send”

We might not always like them flooding our inboxes, but emails are an important aspect of every-day business life. The key is to send helpful emails. And the key to sending helpful emails is to send them at the relevant moment and with helpful details. Sending emails in a SuiteScript removes the natural limitations of the NetSuite UI and allows us to send emails at just the right moment, with hyper-relevant data.

Required Parameters

The N/email module has a few basic parameters you’ll need to know to get started. Let’s take a look!

Author

The Author parameter can be the most confusing of the parameters. Unlike the recipient parameter, which can take either an internal ID or an email address string, the Author parameter can only receive an internal ID of an employee in the system. To find a list of your employees, go to Lists > Employees > Employees in the NetSuite menu. From there, you should be able to find the internal ID for the correct email sender. You can also create a new employee record from there if needed.

Recipients

There are several routes you can take to get the right recipient(s) for the email.

First, you can hard-code the email address as a string in your script. This may be necessary if the email is not in your NetSuite system for one reason or another. Be careful when hard-coding any values in a script, however. This strategy, which is not best practice, may result in future bugs if the email address ever changes.

A second option is to hard-code an Entity record internal ID in your script. This will send the email to the default email recipient on that Entity Record. This is a much better option than hard-coding a string, since the email can be updated on the Entity record without any concerns.

Thirdly, it is actually possible to get the current user’s internal ID. To do this, we can use the Runtime Module.

var currentUser = runtime.getCurrentUser().id;
log.debug("currentUser", currentUser);

The last option we’ll mention is to create a Saved Search in your script to find multiple recipients for the email. This allows us to use any criteria to locate just the right individuals. If you need multiple recipients, just pass in an array into the Recipient parameter.

Subject

This will simply be a string for the subject of the email. Aim to make this as relevant and clear as possible.

Body

The body of the email is where we can be creative!

Here’s an example in the past where we sent an email containing a bullet-point list of some relevant items IDs.

var items = (function () {
    log.debug("itemsToEmail", itemsToEmail); // An array of item IDs []

    var string = "";
    itemsToEmail.forEach(function (item) {
        string += ('<br>• ' + item.toString());
    });

    return string;
})();

The point is that we can use the power of scripting logic to display the most helpful information possible. Since NetSuite also supports HTML in the email body, we can use hyperlinks, line-breaks, and other elements to further format the body.

Optional Parameters

The NetSuite help documentation also gives details for other parameters, such as for Attachments, CC, BCC, Related Records, and Reply To parameters. Be sure to check the official documentation to learn more about these possibilities.

Other Email Module Options

There are a few other infrequently used email module options that follow a similar pattern. We won’t go into detail here, but knowing the basics of sending emails should aid you in exploring the help documentation about these.

Conclusion

The N/email module is relatively straightforward but immensely powerful. We hope you find this article helpful. If you have any questions, feel free to check out the NetSuite help on the N/email module or hit us up in the comments below! And as always, remember to subscribe to our email list to receive your own emails about all things SuiteScript!