Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Get Hostname from any url in server side.

Shantanu_99
Tera Contributor

Hi All,

 

I have one requirement in the email inbound action script, I want to get hostname from the url as below.

In the email, as below url will be provided.

How we can achieve this.

 

                                                 Expected HostName

https://www.google.com           www.google.com

http://www.google.com             www.google.com

https://www.google.com/          www.google.com

http://www.google.com/            www.google.com

www.google.com                        www.google.com

 

Thanks

Shantanu B

1 ACCEPTED SOLUTION

Mark Manders
Mega Patron

If you can get the url from the email, you can try it with something like this:

 

function extractHostname(url) {
    var hostname;
    var url = [your way of getting url from email];

    if (url.indexOf("://") > -1) {
        hostname = url.split('/')[2];
    } else {
        hostname = url.split('/')[0];
    }
    hostname = hostname.split(':')[0].split('?')[0];

 return hostname;
});

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

1 REPLY 1

Mark Manders
Mega Patron

If you can get the url from the email, you can try it with something like this:

 

function extractHostname(url) {
    var hostname;
    var url = [your way of getting url from email];

    if (url.indexOf("://") > -1) {
        hostname = url.split('/')[2];
    } else {
        hostname = url.split('/')[0];
    }
    hostname = hostname.split(':')[0].split('?')[0];

 return hostname;
});

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark