Notification texts go here Contact Us Buy Now!

[C#] Check email Exist using API

[C#] Check email Exist using API
Kiểm tra tài khoản email tồn tại trong C#, nếu các bạn đang có nhu cầu marketing quảng cáo qua email, bạn có danh sách khoảng vài ngàn tài khoản, nhưng trong danh sách địa chỉ đó, làm sao để kiểm tra được email nào hợp lệ, hay còn hoạt động hay không.

Bài viết này, mình sẽ giới thiệu các bạn sử dụng website InfoByIP, có cung cấp cho chúng ta validate email.

Địa chỉ validate email: https://www.infobyip.com/verifyemailaccount.php
Các bạn xem hình bên dưới:

Dưới đây là gói packet gởi đi của Website InfobyIP, mình có thể sử dụng nó để gởi request trong form.

Như hình trên, các bạn sẽ thấy, nó sẽ gởi request tới url: https://www.infobyip.com/verifyemailaccount.php
Form data nó chứa Parametter email, form được gởi theo phương thức POST.
=> Kết quả Response của Request Validate Email.

Các bạn có thể sử dụng phần mềm Postman để test Request, Link download phần mềm Postman
Các bạn sẽ thấy được kết quả trả về, và mình sẽ dùng HtmlAglityPack để get element này ra.

Dưới đây, là demo ứng dụng kiểm tra tài khoản email có tồn tại hay không c#

Hướng dẫn code validate email C#:

Bước 1: Các bạn cần import thư viện XNet Html AglityPack từ Nuget vào.
using xNet;
using HtmlAgilityPack;

Bước 2: Mình sẽ gởi request đến server InfoByIP và lấy kết quả về theo source code bên dưới
private void btnValidate_Click(object sender, EventArgs e)
        {
            try
            {
                HttpRequest httpRequest = new HttpRequest();
                httpRequest.Cookies = new CookieDictionary();
                httpRequest.UserAgent = Http.ChromeUserAgent();
                RequestParams para = new RequestParams();
                para["email"] = txtEmail.Text;

                string html = httpRequest.Post("https://www.infobyip.com/verifyemailaccount.php", para).ToString();


                var page = new HtmlAgilityPack.HtmlDocument();
                page.LoadHtml(html);
                var list = "";
                if (page.DocumentNode.SelectSingleNode("//td[@id='output']//td[@class='left']//img[4]") != null)
                {
                    list = page.DocumentNode.SelectSingleNode("//td[@id='output']//td[@class='left']//img[4]").NextSibling.InnerText;
                }
                else
                {
                    list = page.DocumentNode.SelectSingleNode("//td[@id='output']//td[@class='left']").InnerText;
                    string[] arr = list.Split('.');
                    int count = arr.Length - 1;
                    list = arr[count];

                }

                lblResult.Text = list;

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }

        }

Vậy là xong, rất đơn giản phải không các bạn.
Chúc các bạn thành công!

About the Author

Chia sẽ kiến thức và tư duy sáng tạo của bản thân mỗi ngày cho cộng đồng IT Việt Nam và Thế giới. Chia sẽ thủ thuật lập trình Csharp, Visual Basic, Python, Php, Javascript, Css, Html. Tối ưu hóa Windows, Microsoft, Facebook, Youtube, Chrome...v.v. …

1 comment

  1. Cần gì chương trình e, vào contact google mà lấy thôi
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.
NextGen Digital Welcome to WhatsApp chat
Howdy! How can we help you today?
Type here...