1

I am developing a simple mailing Application in C#, where I want to check the validity of the recipient, In other words we can say that existence of the recipient.

I tried some articles pre written on the same subject concerned, but no luck after implementing the knowledge. I am expecting a solution which can identify the existence of the recipient using Mail Kit Library in C#. Why MailKit only? because my project is based on the same. Other solutions not using MailKit are also invited.

ɐsɹǝʌ ǝɔıʌ
  • 4,440
  • 3
  • 35
  • 56
  • When developing a simple mailing Application you should have basic knowledge about the mail protocol which is used in the world. You do not seem to have this basic knowledge? How will you ever write a, functionally OK, application? – Luuk Jan 18 '23 at 18:55

2 Answers2

1

You can use SmtpClient.Verify method but it requires the server to support the VRFY command. Unfortunately, most SMTP servers do not support it anymore. In that case you will get an error.

using (var client = new SmtpClient())
{                
   client.Connect("smtp.yourserver.com", 465, true);    
   client.Authenticate(name, pass);    
   MailboxAddress m = client.Verify("peter.sands@contoso.com");   
}
ɐsɹǝʌ ǝɔıʌ
  • 4,440
  • 3
  • 35
  • 56
0

Since the OP mentioned that other solutions not using MailKit are also invited, and given the SMTP VRFY command is almost useless nowadays, I would suggest to consider using an email verification service like Verifalia instead, which relies on multiple alternative algorithms to report whether a given email address exists or not - along with a lot of additional technical details.

using Verifalia.Api;

// Initialize the library

var verifalia = new VerifaliaRestClient("your-username", "your-password");

// Validate the email address under test

var validation = await verifalia
    .EmailValidations
    .SubmitAsync("batman@gmail.com", waitingStrategy: new WaitingStrategy(true));

// At this point the address has been validated: let's print
// its email validation result to the console.

var entry = validation.Entries[0];

Console.WriteLine("{0} => Classification: {1}, Status: {1}",
    entry.InputData,
    entry.Classification,
    entry.Status);

// batman@gmail.com => Classification: Deliverable, Status: Success

Disclaimer: I am the CTO of Verifalia.

Efran Cobisi
  • 6,138
  • 22
  • 22
  • Using a service provider will free you from having to update your algorithms when the world changes. And they do change, just see the answers above about VRFY, which are obsolete now. And just to give an alternative to Verifalia, another good email verification service is https://goodforms.com/. Cheap, good privacy, and easy integration ( I am not affiliated) – Göran Roseen Mar 20 '23 at 11:57