How to extract All Emails from a URL using C#?

how to extract All Emails from a URL using C# language and it’s most demanding by sales personnel, advertising industries, digital marketing company
How to extract All Emails from a URL using C#


Hi readers! Hope you must have gone through my previous articles regarding Parsing HTML table, extracting HTML links, and others. Now, we will discuss how to extract All Emails from a URL using the C# language. Here, the class “using System.Text.RegularExpressions;” is very much important for this program. Let’s discuss more briefly about this concept. 

Step #1

Write down ‘using System.Text.RegularExpressions’ along with other namespaces and class names.

Step #2

Declare the public class ExtractProgram

Step #3

Call the URLS through the method public static void Main() as follow


Step #4

Again write down the sub-function for getting the content from the webpage.

public static string GetContent(string URL)
HttpWebResponse response = null;
StreamReader stream = null;

The above two lines start searching for the given URLs within the web. If the output is null or zero or not available, then go for the following functions:

Step #5

Now, you need to create a request object throughout the web URL passed in as follows:

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(URL name);

If the URL name is not accessible, the message ‘webRequest.Timeout = 100000’ would be displayed.
Then, write the following codes along with the stream reader object to get a response from the web page

response = (HttpWebResponse)webRequest.GetResponse();
stream = new StreamReader(response.GetResponseStream());

Step #6

Now, you’ll obtain the contents of the webpage as a string and return the output and proceed to close the program and return the string as output.

return stream.ReadToEnd();
            catch (Exception ex)
            { throw ex;}

Complete Working Code:

Your output will be as follows


Anjan kant

Outstanding journey in Microsoft Technologies (ASP.Net, C#, SQL Programming, WPF, Silverlight, WCF etc.), client side technologies AngularJS, KnockoutJS, Javascript, Ajax Calls, Json and Hybrid apps etc. I love to devote free time in writing, blogging, social networking and adventurous life

Post A Comment: