Reputation: 21
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.
Upvotes: 1
Views: 840
Reputation: 6484
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("[email protected]", 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);
// [email protected] => Classification: Deliverable, Status: Success
Disclaimer: I am the CTO of Verifalia.
Upvotes: 0
Reputation: 4512
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("[email protected]");
}
Upvotes: 1