NetSuite SuiteScript使用公司信息邮箱发邮件报错解决方案咨询
我创建了User Event Script用于发送邮件,希望使用公司信息邮箱发送,但出现如下错误:
{"type":"error.SuiteScriptError","name":"SSS_AUTHOR_MUST_BE_EMPLOYEE","message":"The author internal id or email must match an employee.","id":"","stack":["doSendEmail(N/email)","afterSubmit(/SuiteScripts/emailsend.js:20)"],"cause":{"type":"internal error","code":"SSS_AUTHOR_MUST_BE_EMPLOYEE","details":"The author internal id or email must match an employee.","userEvent":"aftersubmit","stackTrace":["doSendEmail(N/email)","afterSubmit(/SuiteScripts/emailsend.js:20)"],"notifyOff":false},"notifyOff":false,"userFacing":false}
我的代码如下:
/** * @NApiVersion 2.x * @NScriptType UserEventScript * @NModuleScope SameAccount */ define(['N/email', 'N/log'], function(email, log) { function afterSubmit(context) { try { // Get the current record var newRecord = context.newRecord; var emailAddress = 'customer@xyz.com' var name = "oracle netsuite" // Send email email.send({ author: 'companyinformation@xyz.com', // or any other internal id recipients: emailAddress, subject: 'Example Subject', body: 'Dear ' + name + ',\n\nThis is an example email sent from SuiteScript.', }); log.debug('Email Sent', 'An email has been sent to ' + emailAddress); } catch (e) { log.error('Error Sending Email', e); } } return { afterSubmit: afterSubmit }; });
请问是否有可行的解决方法?
这个错误的核心原因是NetSuite的email.send()方法要求author参数必须对应系统内已存在的员工(Employee)记录,无法直接使用未关联员工的公共邮箱。以下是三种可行的解决方式:
方案一:将公司邮箱关联到员工记录
- 在NetSuite后台创建或编辑一个员工档案,把
companyinformation@xyz.com设置为该员工的邮箱地址 - 之后直接使用该员工的内部ID或邮箱作为
author参数值即可
方案二:使用记录创建者作为发件人
如果不需要固定使用公司邮箱,可以直接取当前记录的创建者作为邮件作者,完全符合NetSuite的权限规则:
修改代码中的author参数行:
// 替换原author配置 author: context.newRecord.createdBy, // 取当前记录创建者的内部ID
方案三:配置批准发件箱+设置回复地址(进阶)
若需对外展示公司公共邮箱,可通过以下方式实现:
- 在NetSuite后台配置批准的发件箱,将公司公共邮箱添加进去
- 代码中使用合法的员工ID作为
author,同时通过replyTo参数设置公司邮箱为回复地址:
email.send({ author: 123, // 替换为系统内有效员工的内部ID recipients: emailAddress, subject: 'Example Subject', body: 'Dear ' + name + ',\n\nThis is an example email sent from SuiteScript.', replyTo: 'companyinformation@xyz.com' // 收件人回复时会发送到公司邮箱 });
内容的提问来源于stack exchange,提问作者Maira S

