- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 12:29 AM
Hello Everyone,
I need help in extracting email addresses from error string. The error string will look like this.
450 4.1.2 <eample@example.com>: Recipient address rejected: domain not found
I tried different RegEx but no luck. Any help is appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 12:49 AM
You can use the following script to extract the email address.
var err_str = "450 4.1.2 <eample@example.com>: Recipient address rejected: domain not found";
var invalid_recipient = "";
if (err_str_ln.indexOf("<") != -1 && err_str_ln.indexOf(">") != -1) {
invalid_recipient = err_str.split('<')[1].split('>')[0];
}
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Anvesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 12:54 AM
Yes,
This solution will work for you to extract all emails enclosed in < and >:
// Sample text containing values between < and >
var text = '450 4.1.2 <eample@example.com>: Recipient address rejected: domain not found anotherEmail <example2@text.com>';
// Regular expression to extract values between < and >
var regex = /<([^>]*)>/g;
// Array to store extracted values
var extractedValues = [];
// Extract values using regex
var match;
while ((match = regex.exec(text)) !== null) {
extractedValues.push(match[1]);
}
// Log the extracted values
gs.info('Extracted values:'+ extractedValues);
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 12:55 AM
You can try the following script then.
var err_arr = err_str.split("\n");
var invalid_recipients = [];
for (key in err_arr) {
var err_str_ln = err_arr[key];
if (err_str_ln.indexOf("<") != -1) {
invalid_recipients.push(err_str_ln.split('<')[1].split('>')[0]);
}
}
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Anvesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 12:34 AM - edited 12-12-2023 12:35 AM
Hi,
If your error message format is fixed then you can try below:
var str = "450 4.1.2 <eample@example.com>: Recipient address rejected: domain not found";
var ind1 = str.indexOf('<');
var ind2 = str.indexOf('>');
gs.info(str.substring(ind1+1,ind2));
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 12:45 AM
If you want to use RegEx then try below:
// Sample text containing values between < and >
var text = '450 4.1.2 <eample@example.com>: Recipient address rejected: domain not found';
// Regular expression to extract values between < and >
var regex = /<([^>]*)>/g;
// Array to store extracted values
var extractedValues = [];
// Extract values using regex
var match;
while ((match = regex.exec(text)) !== null) {
extractedValues.push(match[1]);
}
// Log the extracted values
gs.info('Extracted values:'+ extractedValues);
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 12:54 AM
Yes,
This solution will work for you to extract all emails enclosed in < and >:
// Sample text containing values between < and >
var text = '450 4.1.2 <eample@example.com>: Recipient address rejected: domain not found anotherEmail <example2@text.com>';
// Regular expression to extract values between < and >
var regex = /<([^>]*)>/g;
// Array to store extracted values
var extractedValues = [];
// Extract values using regex
var match;
while ((match = regex.exec(text)) !== null) {
extractedValues.push(match[1]);
}
// Log the extracted values
gs.info('Extracted values:'+ extractedValues);
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 12:46 AM - edited 12-12-2023 12:48 AM
Hi @harishbabua8 ,
This will help :
var inputString = "450 4.1.2 <example@example.com>: Recipient address rejected: domain not found";
var emailRegex = /<([^>]+)>/;
var match = inputString.match(emailRegex);
var extractedEmail = match ? match[1] : null;
gs.info("Extracted Email: " + extractedEmail);
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....