I am trying to use mail. body with regex condition to validate my mail to perform my next task. if I get keywords such as ( Accept or Accepted / Reject or Rejected) before the word (From: ) because this validation dependency is on reply mail and I donβt want to take keywords which are in below in the mail body.
the code:
mail.body.ToLower.Contains(Regex.Match(β\w[rejected]+(?=\s+From)β)) or mail.body.ToLower.Contains(Regex.Match(β\w[reject]+(?=\s+From)β))
mail.body.ToLower.Contains(Regex.Match(mail.subject,β\w[rejected]+(?=\s+From)β)) or mail.body.ToLower.Contains(Regex.Match(mail.subject,β\w[reject]+(?=\s+From)β))
Note: Assuming mail.subject will get the email subject from the object.
Kindly check/test the given solution and close the topic by marking the solving post as βsolutionβ
Can do it like this -
Regex.Match(mail.body.ToLower.Contains,β\w[rejected]+(?=\s+From)β)) or
Regex.Match(mail.body.ToLower.Contains,β\w[reject]+(?=\s+From)β))
System.Text.RegularExpressions.Regex.IsMatch(mail.Body.ToLower.Contains,β\w[rejected]+(?=\s+From)β) Or System.Text.RegularExpressions.Regex.IsMatch(mail.Body.ToLower.Contains,β\w[reject]+(?=\s+From)β)
or without contains , I will test it now
System.Text.RegularExpressions.Regex.IsMatch(mail.Body.ToLower,β\w[rejected]+(?=\s+From)β) Or System.Text.RegularExpressions.Regex.IsMatch(mail.Body.ToLower,β\w[reject]+(?=\s+From)β)
Please change βFromβ to βfromβ in pattern to get a match since you are already converting the email content to lowercase.
System.Text.RegularExpressions.Regex.IsMatch(mail.Body.ToLower,β\w[rejected]+(?=\s+from)β) Or System.Text.RegularExpressions.Regex.IsMatch(mail.Body.ToLower,β\w[reject]+(?=\s+from)β)
I already highlighted this in previous post. Thank you.
I want Boolean value for my if condition ( IsRejected / IsAccepted ) these are my variables and I want to use these values to check either mail body contains accept or reject via Regex to take the mail body ( plus this mail body is actually a replay and it contains multiple replies which might have reject as keyword on pervious mails but on latest mails the body contains accept by sender, so I want to use this regex condition to take value above last (From:) in mail body to avoid taking previous replies
choose either accept or reject to continue the process
Best Regards,
Ahmed
so as you can see in this mail reply there are total 3 keywords(accept, accept. reject) so I run this as normal [ IsAccepted = mail.body.ToLower.Contains(βacceptβ) ]
[ IsRejected = mail.body.ToLower.Contains(βrejectβ) ]
it will take the reject value