Email Capture Plugin Implementation

Email Capture Plugin Implementation
We can implement email capture functionality in NetSuite account to capture emails inorder to create email message records or use email content data.
This is possible if the account already has email capture plugin installed. A email capture plugin file can be created in javascript and uploaded to NetSuite account using the
plugin installed. After uploading the plugin file an email id will be generated in NetSuite email capture plugin implementation page. This email can be used as a cc email address to capture any email send from
outside the NetSuite account.
Steps:

  • Verify if the NetSuite account has a pre-installed email capture plug-in. Use the navigation:
    Customization> Plug-ins> Manage Plug-ins (If already installed, we can see the title Email capture plug-in in this page)
  • Create a email-capture plug-in in JavaScript and fetch required data from email and send it to a suitelet(using post method).
    Use the sample code for reference:
 * *************************************************************************

/**
 * name of the function MUST be process
 */
function process(email) {
    var fromAddress, toAddress = [], ccAddress, emailSubject, emailBody, attachmentsInfo=[];

    try{
        //Print out FROM email address
        fromAddress = email.getFrom();
        nlapiLogExecution('debug', 'From Email Address', fromAddress);

        //Print out TO email addresses
        var to = email.getTo();
        for (var index=0; index<to.length; index++) {
            //nlapiLogExecution('debug', 'To Email Address', to[index].getEmail());
            toAddress.push(to[index].getEmail());
        }
        //nlapiLogExecution('debug', 'To Email Address', JSON.stringify(toAddress));

        //Print out CC email Addresses
        ccAddress = email.getCc();
        //nlapiLogExecution('debug', 'CC Email Addresses', ccAddress);

        //Print out Email Subject
        emailSubject = email.getSubject();
        //nlapiLogExecution('debug', 'Email Subject', emailSubject);

        //Print out Email TEXT Body
        emailBody = email.getTextBody();
        //nlapiLogExecution('debug', 'Email Text Body', email.getTextBody());

        //Grab an Array of ALL Attachments
        var attachFiles = email.getAttachments();
        nlapiLogExecution('debug', 'Number of attachments', attachFiles.length);
        for (var f=0; f < attachFiles.length; f++){
            nlapiLogExecution('debug', 'Name of attachment', attachFiles[f].getName());
            nlapiLogExecution('debug', 'Type of attachment', attachFiles[f].getType());
            nlapiLogExecution('debug', 'Value of attachment', attachFiles[f].getValue());
            attachmentsInfo.push({
                fileName: attachFiles[f].getName(),
                fileType: attachFiles[f].getType(),
                fileContent: attachFiles[f].getValue()
            });
        }
        sendToSuitelet(fromAddress, toAddress, ccAddress, emailSubject, emailBody, attachmentsInfo);
    }catch (err){
        nlapiLogExecution('debug', 'Error at email capture plugin implementation', err);
    }

}
/**
 * function to send data to suitelet
 * @param {String}  fromAddress- Email id of sender
 * @param {String}  toAddress- Recipient email id
 * @param {String}  ccAddress- Email id of cc
 * @param {String}  emailSubject- Subject of email
 * @param {String}  emailBody- Content of the email body
 * @param {Object[]}  attachObjArray- Array of attachment objects with file name, type and content
 * @param {String} attachObjArray.fName - refer to the filename
 * @param {String} attachObjArray.fType - refer to the filetype
 * @param {String} attachObjArray.fContent - refer to the file contents
 * @since 2015.2
 */
function sendToSuitelet(fromAddress, toAddress, ccAddress, emailSubject, emailBody,attachObjArray){
    try
    {
        var emailData = {};
        emailData = {"from" : fromAddress, "to" : toAddress, "cc" : ccAddress, "subject" : emailSubject, "body" : emailBody, "attachObjArray": attachObjArray};
        var dataSend = JSON.stringify(emailData);
        //nlapiLogExecution('debug', 'Email data JSON', dataSend);
        var url = nlapiResolveURL("SUITELET", "customscript_jjslemailcaptureswyft77", "customdeploycustomdeploy_jj_sl_email_cap", "external");
        //nlapiLogExecution('debug', 'URL of suitelet', url);//Checking whether url is obtained correctly
        var response = nlapiRequestURL(url, dataSend, {}, null,'POST' );

    }catch ( err ) {
        nlapiLogExecution('debug', 'Error at email data transfer function', err);
    }
}
  • Upload the implementation JavaScript using the navigation: Customization> Plug-ins> Plug-in implementation> New> Choose plugin file and Click Create Plug-in implementation
  • Once the email plug-in implementation is created we can see the same in Customization> Plug-ins> Manage Plug-ins under Email capture plug-in. Check the tick mark and click save.
  • The email id near to the plug-in implementation can be used as cc address for capturing any email send using Gmail or other mail services.(the email id will look like:emails.4996035_SB1.497.f06f1ad1…..)

Leave a comment

Your email address will not be published. Required fields are marked *