Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Set 'To' email address in a mailto Script

Terri Welch
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

Vishal Jaswal
Giga Sage

Hello @Terri Welch 
If there is a TO email set in the e-mail notification and you want to set the same in your mailto script used in same email notification in message html then I believe it is not possible, however can be achievable using event registry (an example shared here: https://www.servicenow.com/community/itsm-forum/how-to-automate-for-notifying-if-a-task-isopened/td-... 


Hope that helps!

Ankur Bawiskar
Tera Patron

@Terri Welch 

can you try this in your email script?

var emailAddress = "user@example.com";
        var name = "User Name";
        email.setEmailTo(emailAddress, name);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

vermaamit16
Kilo Patron

Hi @Terri Welch 

 

You can make use of 

email.addRecipient("user.name@example.com"); // replace with your to email ID

to set the To Email address. It is working as expected. Refer below screenshots -

 

AmitVerma_0-1742271936146.png

 

AmitVerma_1-1742271956871.png

Please give it a try and let me know the results.

 

Thanks & Regards

Amit Verma

Thanks and Regards
Amit Verma

Here is the situation:
I have a notification that has the following links:

TerriWelch_0-1742317741247.png

These links are created with  'mailto script' in the notification:

TerriWelch_1-1742317870313.png

When the link is clicked in the email - I need to set the TO address.  Currently it is being set by a system property (I cannot change the system property - this is ONLY for this one notification)

TerriWelch_2-1742318079598.png

The mail_script did not work with in the mailto Template or the original email.