Add CC and BCC to Email templates

Sindhu50
Tera Contributor

Hi,

  1. I have a notification that includes links to several email templates.

  2. When a user selects any template, it open's a new email with the "To" field automatically populated with our instance mail ID

    I would like some guidance on how to achieve the following functionality

               Within that same email, they should also be able to see the CC and BCC recipients, which are unique based on Record-> location -> email records.

Could anyone please advise how I can implement this?

1 ACCEPTED SOLUTION

Robert H
Mega Sage

Hello @Sindhu50 ,

 

This is not possible via Email Templates since they are static. But you can achieve this with Email Scripts. Here is an example. Just change the name and the values of the first four variables as per your requirements.

 

Name: email.link.with.dynamic.recipients

Script:

(function runMailScript(current, template, email, email_action, event) {

    var linkText = 'Click here to reply';
    var subject = 'Email subject of reply goes here';
    var cc = [
        current.assigned_to.email.toString(),
        current.assignment_group.manager.email.toString()
    ].toString();
    var bcc = current.opened_by.email.toString();
    
	var to = gs.getProperty('instance_name') + '@service-now.com';
	var body = email.watermark;

    var url = gs.getMessage('mailto:{0}?cc={1}&bcc={2}&subject={3}&body={4}', [
        to, cc, bcc, encodeURIComponent(subject), encodeURIComponent(body)
    ]);
    var link = gs.getMessage('<a href="{0}">{1}</a>', [url, linkText]);

    template.print(link);

})(current, template, email, email_action, event);

 

Then put this in the Message of your Notification, where the email link shall appear:

${mail_script:email.link.with.dynamic.recipients}

 

The notification will look like this:

RobertH_0-1744832294831.png

 

Clicking the link will open a new Email:

RobertH_1-1744832376450.png

Regards,

Robert

View solution in original post

1 REPLY 1

Robert H
Mega Sage

Hello @Sindhu50 ,

 

This is not possible via Email Templates since they are static. But you can achieve this with Email Scripts. Here is an example. Just change the name and the values of the first four variables as per your requirements.

 

Name: email.link.with.dynamic.recipients

Script:

(function runMailScript(current, template, email, email_action, event) {

    var linkText = 'Click here to reply';
    var subject = 'Email subject of reply goes here';
    var cc = [
        current.assigned_to.email.toString(),
        current.assignment_group.manager.email.toString()
    ].toString();
    var bcc = current.opened_by.email.toString();
    
	var to = gs.getProperty('instance_name') + '@service-now.com';
	var body = email.watermark;

    var url = gs.getMessage('mailto:{0}?cc={1}&bcc={2}&subject={3}&body={4}', [
        to, cc, bcc, encodeURIComponent(subject), encodeURIComponent(body)
    ]);
    var link = gs.getMessage('<a href="{0}">{1}</a>', [url, linkText]);

    template.print(link);

})(current, template, email, email_action, event);

 

Then put this in the Message of your Notification, where the email link shall appear:

${mail_script:email.link.with.dynamic.recipients}

 

The notification will look like this:

RobertH_0-1744832294831.png

 

Clicking the link will open a new Email:

RobertH_1-1744832376450.png

Regards,

Robert