Set From address dynamically in email client template
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2024 12:38 PM
Hello I am trying to configure am email client template where sender address 'From' has to be dynamically populated based on the Assigned to field on a case table. Assigned to a specific user is a reference field and Email value has to be fetched from the user table. I have tried many ways configuring the script include and calling it from email client template (sender configuration) but nothing seems to work out. Can someone provide any workaround on how to achieve this? Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2024 12:29 AM
Hi @PrashanthB80186 ,
You can add a mailscript which sets the from address.
Within the mailscript you do your magic by retrieviing the desired from address and setting it.
Example:
email.setFrom(current.caller_id.email);
email.setReplyTo("joe.employee@yourcompany.com");
More information:
Hope this helps. If it does, please mark as helpful or as solution.
Regards,
Hayo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2024 04:16 AM
How to call this email script from email email client template?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2024 11:17 PM - edited ‎11-11-2024 11:26 PM
You can add a ${mail_script:script name} embedded script tag to the body of the email notification or template, replacing script name with the name of the script you created. This makes it easy to use the same scripts in multiple email notifications or templates.
You can add the script everywhere in the mail.
Since this is regarding the from, I would add it on the top-line, so you quickly see if the script is used.
More information can be found here: https://www.servicenow.com/docs/bundle/xanadu-platform-administration/page/script/server-scripting/c...
An example can be found in the ootb mails, like the "Admin Center Content Shared" email.
Mail script with email.setFrom:
Regards,
Hayo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2024 12:45 AM
At the Send Configuration section on the form of Email Client Template, you can select the From Generation Type method to determine how the Sender (From address) in the email client message is generated.
Use this method only if you want a different From address than the one defined in your SMTP email account.
- None: The From address isn’t generated in the email client message.
- SMTP Email Account: Use the From address of the SMTP email account for the instance as the sender.
- Select From List: Choose from a list of allowable From addresses defined in the Email Client From Address [sys_email_client_from_address] table.
- Script: Run a GlideRecord query on the Email Client From Address [sys_email_client_from_address] table.For example, the following script sets the From address based on the location of the incident caller:
(function (fromAddressQuery, targetRecord) {
// targetRecord is incident for this template
var location = targetRecord.caller_id.country;
if (location == 'us')
fromAddressQuery.addQuery('email_address', 'servicedesk.us@example.com');
else if (location == 'japan')
fromAddressQuery.addQuery('email_address', 'servicedesk.jp@example.com');
else if (location == 'uk')
fromAddressQuery.addQuery('email_address', 'servicedesk.uk@example.com');
})(fromAddressQuery, targetRecord);
- Text: Enter the email From address to be used in the client.
Ref: Create an email client template > Sender Configuration
Cheers,
Tai Vu