How to set the 'Email user label' from script?

peterraeves
Mega Guru
How to set the 'Email user label' from script or notification form?
 
You can modify the 'From' field on an email by using the method 'setFrom' or by setting it in the field 'From' on the Notification.
 
 
This works and emails look like they are arriving from another email address. The problem is that the user label is still containing 'ServiceNow', since that is set at the SMTP account, which is fine. Though in some special cases, where we set the From field directly from script, we also want to set the user label accordingly.
 
So, how do I change email user label for specific notifications?

 

1 ACCEPTED SOLUTION

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi,

You can do it 2 ways
1) In the notification, you can use the below format in the from field
TEST NAME <ab@gmail.com>

2) If you want to use mail script, use the format below.
email.setFrom("TEST NAME <ab@gmail.com>");

Note: if you are using mail script, the From should be blank in notification otherwise it will not work as From field in notification take precedence over the email script value.

Hope this will fit your need.

If I have answered your question, please mark my response as correct and/or helpful so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.

Thank you

Cheers
Alberto

View solution in original post

5 REPLIES 5

Priya Shekar
Giga Guru

Can you give some example? so that it will be easy.