MailKit SMTPClient连接可以打开多长时间

发布于 2025-01-27 19:38:37 字数 149 浏览 3 评论 0原文

我将MailKit用于我的ASP.NET核心应用程序,并创建一个SMTPCLIENT对象,然后将其连接到Office365,并使用用户名和密码对用户进行身份验证。该连接可以打开多长时间,直到它到期或需要重新验证?另外,是否有一种方法可以在未在到期时间发送电子邮件的情况下保持连接活力?

I use mailkit for my ASP.Net Core application and create a SMTPClient object which I then connect to Office365 and authenticate my user with a username and password. How long can this connection be open until it expires or needs to be reauthenticated? Also, is there a way to keep the connection alive without sending an email at the expiration time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩套路吗 2025-02-03 19:38:37

要使客户端连接到服务器活着(无论是使用iMapclient,pop3client还是smtpclient),您可以使用noop()或noopasync()方法将命令发送到服务器,该命令只能执行“否”让服务器知道客户端仍在那里,并希望连接保持活力。至少在理论中,这将起作用。

也就是说,在任何漫长的时间内保持SMTP连接的生命可能并不是不错的网络。

大多数SMTP服务器都会期望客户端连接,刷新其出站消息队列(通过发送排队的每个消息),然后立即断开连接,一些较大的免费邮件服务器可能会忽略NOOP命令并在某些设置后与客户端断开连接一段时间。

例如,IMAP规范指出,服务器应在客户端的最后一个命令后至少保持连接至少30分钟,但实际上,Gmail只能使该连接保持不到10分钟。

据我所记得的,SMTP规范在我的头顶上都没有任何建议,只要在客户端的最后一个命令之后保持连接的时间多长时间,因此某些服务器可能需要比其他服务器更频繁的NOOP命令,并且em>某些甚至可能有最长的时间,他们将允许您保持该连接的活力,无论您是否发送NOOP命令。

tl; dr:

noop命令(通过noop()或noopasync()方法)理论上,如果频繁发送足够的发送,则可以使连接保持活力,但是我不会可靠地依赖此工作。

To keep a client connection to a server alive (whether it be using the ImapClient, Pop3Client, or the SmtpClient), you can use the NoOp() or NoOpAsync() methods to send a command to the server that does "nothing" but to let the server know that the client is still there and wants the connection to remain alive. At least in theory this will work.

That said, it's likely not considered good netiquette to keep an SMTP connection alive for any lengthy period of time.

Most SMTP servers are going to expect clients to connect, flush their outbound message queues (by sending each message that is queued up) and then immediately disconnecting and some of the bigger free mail servers may ignore NOOP commands and disconnect the client anyway after some set period of time.

For example, the IMAP specification states that servers should keep a connection alive for at least 30 minutes after the client's last command, but in practice, GMail will only keep that connection alive for less than 10 minutes.

The SMTP specification, as far as I can remember off the top of my head, makes no such suggestion as far as how long to keep the connection alive after the client's last command, so some servers may require more frequent NOOP commands than others and some may even have a max period of time that they'll allow you to keep that connection alive for regardless of whether you send those NOOP commands.

TL;DR:

The NOOP command (via the NoOp() or NoOpAsync() methods) will theoretically keep the connection alive if sent frequently enough, but I would not depend on this working reliably.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文