如何在发送邮件之前验证SMTP凭证? [英] How to validate smtp credentials before sending mail?

查看:666
本文介绍了如何在发送邮件之前验证SMTP凭证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要发送邮件之前验证在 SmtpClient 实例设置的用户名和密码。使用这个code:

I need to validate the username and password set in an SmtpClient instance before sending mail. Using this code:

SmtpClient client = new SmtpClient(host);
client.Credentials = new NetworkCredential(username,password);
client.UseDefaultCredentials = false;

// Here I need to verify the credentials(i.e. username and password)
client.Send(mail);

我如何可以验证标识的凭据是否允许用户连接和发送邮件?

How can I validate whether the user identified by the credentials is allowed to connect and send a mail?

推荐答案

有没有办法。

SmtpClient bascially无法验证usernamepassword而不接触送达连接。

SmtpClient bascially can not validate the usernamepassword without contacting the serve it connects to.

你可以做的就是做SmtpClient外,通过打开一个TCP连接到服务器...但认证可以根据服务器的配置是复杂的。

What you could do is do it outside SmtpClient, by opening a TCP connection to the server... but authentication CAN be complicated depending how the server is configured.

我会问为什么你需要知道发送过吗?正常的行为,恕我直言,是将包装发送适当的错误处理在这里捕获异常。

May I ask WHY you need to know that before sending? normal behavior IMHO would be to wrap sending in appropriate error handling to catch exceptions here.

这篇关于如何在发送邮件之前验证SMTP凭证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆