MailKit SMTP Connection Lifetime #1929
Replies: 1 comment 1 reply
-
"Depends" Are you sending out 1 message, waiting 30 seconds, and then sending out the next message? In normal cases, it doesn't take more than a second or two to make a TCP/IP connection to an SMTP server, so keeping the connection alive might not make a ton of sense. But if it takes a minute to connect because there is a ton of latency, then sure, it might make sense. Also keep in mind that keeping that SmtpClient connection alive will require you to periodically call SmtpClient.NoOp() or NoOpAsync() or the SMTP server will likely drop your connection. How does that play into your app design? Is that something that will be fairly easy for you to implement? FWIW, I don't think it'd be worth keeping an SmtpClient idle for more than a minute or two and so I'd say that even if you were to implement some sort of NOOP thread/loop to keep an SmtpClient's connection alive, it probably doesn't make sense to keep it idle longer than that. I'm not even sure if the Exchange server will allow you to keep a connection open for very long, even if you do send it periodic NOOPs. So that's something to consider as well...
No, there's no way to do that. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Our app needs to send emails for various purposes and we recently replaced old System.Net.Mail.SmtpClient with MailKit.
We need to support both OAuth and Basic authentication depending on user configuration.
I have two questions.
Is it advisable to keep the connection open for a long time? As an example, if we need to send emails every 30 seconds, is it advisable to reuse the same connection for hours or for days? Or should we re establish a new connection every few minutes or so?
Also, when authenticating with OAuth using AuthenticateAsync method, it there a way to pass a 'handler' to generate the OAuth token rather than passing the generated 'token'?
Beta Was this translation helpful? Give feedback.
All reactions