Tip 14 : Solve SmtpClient issues of delayed email and high CPU usage
- by StanleyGu
1. It is quite straightforward using SmtpClient class to send out an email
2. However, when you step through the above code executing smtpClient.Send(), you will notice about 2 minutes delay in receiving the email.
3. My first try to solve the issue of delayed email is to set MaxIdleTime=1
4. The first try solves the issue of delayed email very well but introduces another issue: high CPU usage. The CPU usage of my deployed windows service is consistently at 50%, which is much higher than the expected near-zero CPU usage.
5. The second try is to set MaxIdleTime=2, which solves the both issues.