Developers running into an issue where email.send(options) is triggered, but email is not sent when using External URL of the Suitelet and it sends email when internal URL is used on test drives, development accounts.
It is important to note that on test, development accounts there Email Options for routing is set to Send Email to Logged in User and it is hard-coded. On Sandbox and Release Preview accounts, in order for the emails to be sent when using External URL of the Suitelet, Send email To field should be set to specific email address under Setup > Company > Email Preferences > Email Options.
Since this value is hard-coded on test drives and development accounts, it is not able to authenticate the session with the currently logged in user as there is no such user when email.send(options) or nlapiSendEmail is triggered.
Please note that there is no such restriction on Production accounts, the functions will be executed and emails will be sent successfully.
This behavior can be tested on Sandbox, Release Preview, Production and development accounts by using the sample Suitelet below to get better understanding:
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(['N/record', 'N/email', 'N/log', 'N/runtime'],
function(record, email, log, runtime) {
function onRequest(context) {
var req = context.request;
var res = context.response;
var userObj = runtime.getCurrentUser();
log.debug('user is: ', JSON.stringify(userObj));
log.debug('role', userObj.role);
email.send({
author: 5,
recipients: 5,
subject: 'Test suitelet email',
body: 'suitelet email body'
});
log.debug('Done','email sent');
}
return {
onRequest: onRequest
};
});