Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想检查给定的用户名和密码是否可以使用 SMTP 邮箱。我正在使用该SmtpClient.Send方法发送电子邮件,但在发送之前,我想检查提供的凭据是否正确,并检查 SMTP 服务器是否有效。
SmtpClient.Send
我怎样才能从 C# 做到这一点?
我不认为 API 提供了相当于“有效”类型的查询。但是,当您查看文档时,它指出SmtpException如果发送失败,则会抛出 an ;失败的两个原因包括你在寻找什么
SmtpException
因此,处理该异常并检查它是否确实是由于身份验证失败或服务器连接失败应该为您提供所需的内容。