Set 'To' email address in a mailto Script

Terri Welch
ServiceNow Employee
ServiceNow Employee

Can I set the 'TO' address in an mailto script?  It reads from the system property, but I only want to change it for a specific email, not system wide.  Let's say I want it to go to my personal email instead of the system email.  This is NOT for a reply email - it is for a mailto: link in my email.

1 ACCEPTED SOLUTION

Hello @Terri Welch 

Dummy email script

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

          // Add your code here

   var approverEmail = "abc@gmail.com"; // Replace 
   var subject = "Project Approval Decision";
   // Generate mailto links with action in the subject - please modify them as per your requirement
   var acceptLink = 'mailto:' + approverEmail + '?subject=' + encodeURIComponent(subject + ' - Accept');
   var deferLink = 'mailto:' + approverEmail + '?subject=' + encodeURIComponent(subject + ' - Defer');
   var declineLink = 'mailto:' + approverEmail + '?subject=' + encodeURIComponent(subject + ' - Decline');
   // Output the links for use in the email body
   template.print('<p>Click below to respond:</p>');
   template.print('<p><a href="' + acceptLink + '"> Accept</a></p>');
   template.print('<p><a href="' + deferLink + '"> Defer</a></p>');
   template.print('<p><a href="' + declineLink + '"> Decline</a></p>');


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


You can modify this dummy script to have different email address for accept, defer and decline.
Dummy Email Notification Message HTML

Hi

To waste your time, a request has been submitted to you for accept/reject/defer by clicking on one of the options below:

${mail_script:dummy_script}

Thanks
ServiceNow


Validation results:

vishal_jaswal_0-1742321172414.png



Hope that helps!




Hope that helps!

View solution in original post

6 REPLIES 6

Hello @Terri Welch 

Dummy email script

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

          // Add your code here

   var approverEmail = "abc@gmail.com"; // Replace 
   var subject = "Project Approval Decision";
   // Generate mailto links with action in the subject - please modify them as per your requirement
   var acceptLink = 'mailto:' + approverEmail + '?subject=' + encodeURIComponent(subject + ' - Accept');
   var deferLink = 'mailto:' + approverEmail + '?subject=' + encodeURIComponent(subject + ' - Defer');
   var declineLink = 'mailto:' + approverEmail + '?subject=' + encodeURIComponent(subject + ' - Decline');
   // Output the links for use in the email body
   template.print('<p>Click below to respond:</p>');
   template.print('<p><a href="' + acceptLink + '"> Accept</a></p>');
   template.print('<p><a href="' + deferLink + '"> Defer</a></p>');
   template.print('<p><a href="' + declineLink + '"> Decline</a></p>');


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


You can modify this dummy script to have different email address for accept, defer and decline.
Dummy Email Notification Message HTML

Hi

To waste your time, a request has been submitted to you for accept/reject/defer by clicking on one of the options below:

${mail_script:dummy_script}

Thanks
ServiceNow


Validation results:

vishal_jaswal_0-1742321172414.png



Hope that helps!




Hope that helps!

Thank you vishal_jaswal - This works exactly as I needed.