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

3
2个回答

3

在我处理这个问题时最担心的是必须发送电子邮件来检查凭据是否有效。因此,在尝试了很多在线提供的解决方案后,我想出了自己可行的方法来测试电子邮件凭据

我使用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;
    }

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接