检查电子邮件凭据是否存在

问题描述 投票:1回答:2

[有很多问题问smtp服务器是否像Testing SMTP server is running via C#Can I test SmtpClient before calling client.Send()?一样工作,它们通过向smtp服务器发送命令来完成检查工作。他们从不使用任何凭据进行测试。所以我想知道是否有一种方法可以在不发送邮件的情况下检查这些登录名和密码在此smtp服务器上是否有效?

c# smtp credentials
2个回答
0
投票

SMTP不允许您不发送电子邮件就登录。

请看以下内容:

How to validate smtp credentials before sending mail?


0
投票

当我处理此问题时,我最担心的是找到一种解决方案,无需发送电子邮件来检查凭据是否有效。因此,在尝试了一系列在线提供的解决方案之后,我想出了我自己可以接受的解决方案,以[[测试电子邮件凭据:

我使用MailKit来帮助我。

public static bool ValidateCredentials(string username, string password, string server, int port, bool certificationValidation) { try { using (var client = new MailKit.Net.Smtp.SmtpClient()) { try { client.ServerCertificateValidationCallback = (s, c, h, e) => certificationValidation; client.Connect(server, port, false); client.Authenticate(username, password); client.Disconnect(true); return true; } catch (Exception ex) { Console.WriteLine(string.Format("ValidateCredentials Exception: {0}", ex.Message)); } } } catch (System.Exception ex) { Console.WriteLine(string.Format("ValidateCredentials Exception: {0}", ex.Message)); } return false; }

© www.soinside.com 2019 - 2024. All rights reserved.