In this article I will explain with an example, how to resolve the following error while sending email using MailKit in .Net.
MailKit.ServiceNotAuthenticatedException: 5.7.0 Authentication Required.
Error
The following error occurs when you try to send email with MailKit using credentials in your .Net application.
5.7.0 Authentication Required. For more information, go to
5.7.0 https://support.google.com/mail/?p=WantAuthError v124-20020a626182000000b006d96d753ca0sm25381832pfb.38 - gsmtp
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: MailKit.ServiceNotAuthenticatedException: 5.7.0 Authentication Required. For more information, go to
5.7.0 https://support.google.com/mail/?p=WantAuthError v124-20020a626182000000b006d96d753ca0sm25381832pfb.38 - gsmtp
Solution
This error means that the SMTP Server requires Authentication and hence when using MailKit, the Authenticate method of SmtpClient class object must be called with valid UserName and Password of the SMTP Server.