MailKit fails to authenticate properly with passwords containing certain characters

Richard Rosenheim 66 Reputation points
2024-04-29T22:19:47.19+00:00

I have the following block of code to send an email using MailKit:

using (var smtp = new MailKit.Net.Smtp.SmtpClient())                 
{
   smtp.Connect("mail.somedomainname.com", 587, SecureSocketOptions.StartTls);
   smtp.Authenticate("EMAIL ADDRESS GOES HERE", @"PASSWORD GOES HERE");
   smtp.Send(email);
   smtp.Disconnect(true);
} 

When the password in the Authenticate call contains special characters, the authentication will fail. Does anyone know which special characters MailKit will allow/work properly with?

I'm using Visual Studio 2022. .NET Framework 4.8, MailKit version is 3.4.0.0 (runtime version 4.0.30319).

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,466 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,399 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 58,121 Reputation points
    2024-04-29T22:25:16.59+00:00

    it is most likely an encoding issue. see this thread:

    https://github.com/jstedfast/MailKit/issues/1539


0 additional answers

Sort by: Most helpful