How can I include the sender's email address in the condition of an inbound action?

Vijay Kumar4
Mega Guru

VijayKumar4_0-1744126415788.png

The inbound action I’ve set up is meant to create a request when an email is received. However, the scenario involves a forwarded email — specifically, emails forwarded from abc@gmail.com to dev@service-now.com. I only want to create a request if the original sender is abc@gmail.com. How can I add a condition to check for the original sender's address? Also, should the Type be set to Forward in this case?

2 ACCEPTED SOLUTIONS

Robbie
Kilo Patron
Kilo Patron

Hi @Vijay Kumar4,

 

In the email action 'Actions' tab you can use the following syntax to obtain both the senders email and the original senders email (from where it was forwarded from:

  • email.origemail 
  • email.from

Below is a great article from @jonnyseymour who explains in more detail - Kudos jonny:

https://www.servicenow.com/community/developer-blog/the-difference-between-inbound-email-action-vari...

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie

View solution in original post

Hello @Vijay Kumar4 

 

Did you add the condition in the "CONDITION" field directly as I said in my previous reply ? 

 

Because it will not allow the inbound action to proceed if sender is not this. 

 

As for your "email.origemail" its because it will returns only when its included in email headers. 

 

""Contains the address of the email sender as listed in the email Headers field"".

 

Refer this document by servicenow - https://www.servicenow.com/docs/bundle/yokohama-platform-administration/page/administer/notification...

 

And your header wouldn't contains it that's why it returns same in both original and sender. 

 

I hope this answers your queries.

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

View solution in original post

5 REPLIES 5

Robbie
Kilo Patron
Kilo Patron

Hi @Vijay Kumar4,

 

In the email action 'Actions' tab you can use the following syntax to obtain both the senders email and the original senders email (from where it was forwarded from:

  • email.origemail 
  • email.from

Below is a great article from @jonnyseymour who explains in more detail - Kudos jonny:

https://www.servicenow.com/community/developer-blog/the-difference-between-inbound-email-action-vari...

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie

// Convert everything to lowercase for reliable comparison
var sender = email.from.toLowerCase();
var orgSender = email.origemail.toLowerCase();
var body = email.body_text.toLowerCase(); // Prefer body_text over body to avoid HTML formatting

// Check if the sender is abc@gmail.com or if the original message contains 'From: abc@gmail.com'
if (sender == 'abc@gmail.com ') {

    current.requested_for = gs.getUserID();
    current.short_description = email.subject;
	current.description = 'Original Email: '+orgSender+'\n'+'Sender: '+sender;
    current.contact_type = "email";

    current.insert();

} 

@Robbie Thanks for the response. I’m facing another issue - even when I check the sender in the Action script, a request is still being created if an email is sent from a different address. However, the assigned values are not being populated. How can I prevent the request from being created entirely if the sender condition is not met?

Shivalika
Mega Sage

Hello @Vijay Kumar4 

 

Yes, set it to Forwarded. 

 

And in the conditions field just add below 👇 code - 

 

email.from == abc@gmail.com

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

@Shivalika Thanks for the response. I’m facing another issue - even when I check the sender in the Action script, a request is still being created if an email is sent from a different address. However, the assigned values are not being populated. How can I prevent the request from being created entirely if the sender condition is not met?

// Convert everything to lowercase for reliable comparison
var sender = email.from.toLowerCase();
var orgSender = email.origemail.toLowerCase();
var body = email.body_text.toLowerCase(); // Prefer body_text over body to avoid HTML formatting

// Check if the sender is abc@gmail.com or if the original message contains 'From: abc@gmail.com'
if (sender == 'abc@gmail.com ') {

    current.requested_for = gs.getUserID();
    current.short_description = email.subject;
	current.description = 'Original Email: '+orgSender+'\n'+'Sender: '+sender;
    current.contact_type = "email";

    current.insert();

}