Sending Mail Using OAuth 2.0: The Handshake Failed Due to an Unexpected Packet Format

Hi Team,
I am using OAuth 2.0 using aspose.email version 21.4 i.e. the latest one. My .net application is deployed on server. While sending email using Microsoft account i get the following error while creating connection. The same works fine on local machine but not on server.
Host : smtp.office365.com
Port 587
SSL True
I tried google account with OAuth 2.0 it works fine on server. Only issue is while creating connection in case of microsoft account

An error occured while connecting SmtpClient: AsposeException: The handshake failed due to an unexpected packet format.—> AsposeException: The handshake failed due to an unexpected packet format.—> AsposeException: The handshake failed due to an unexpected packet format.—> System.IO.IOException: The handshake failed due to an unexpected packet format.at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)at #=z9GgAynulMrKCEo5FMLWx6xhJGRYeptNaNQ==.#=zdJ3exyQaSWMO()at #=z9GgAynulMrKCEo5FMLWx6xhJGRYeptNaNQ==.Read(Byte[] #=zibEnB0k=, Int32 #=zArbTweQ=, Int32 #=zzHA$ars=)at #=zkm$6G_WnpF9EAMEKBRwOQmxii9_xHy0Z5w==.Read(Byte[] #=zibEnB0k=, Int32 #=zArbTweQ=, Int32 #=zzHA$ars=)at #=zE1aFXTK3Xrd9Cc7QUqWVRSA=.#=zm41E2xM=(Byte[] #=zibEnB0k=, Int32 #=zArbTweQ=, Int32 #=z2lhN$20=)at #=zE1aFXTK3Xrd9Cc7QUqWVRSA=.#=zm41E2xM=(Byte[] #=zibEnB0k=)at #=zTJsb7ZZMXBoGMY9hsiXkI_QQh8a0WWi1sM1UOC4=.#=zQzNTkaI=()at #=zTJsb7ZZMXBoGMY9hsiXkI_QQh8a0WWi1sM1UOC4=.#=z6BkqZ1w=(Object #=z3r3LHIk=) — End of inner exception stack trace —at #=z9iSzmGr8Rv2NoVfjwFPLBDnkweR5.#=zGRdyl88=(IAsyncResult #=zoiuWW04=)at #=z9iSzmGr8Rv2NoVfjwFPLBDnkweR5.#=zXYpRvxI=()at #=zNlI1$ziqDhgatrogOXJHTlo8CHk6zfYu8wsQolA=.#=zB3ClBIlpTzmvwsjRNQ==(Boolean #=zE4HboUDbN$DU)at #=zNlI1$ziqDhgatrogOXJHTlo8CHk6zfYu8wsQolA=.#=ziJUkI247MXAv(#=ztoDMvfZVownzj78Wg79zOIGCZ5Qa #=zRbfYIHe$J83f)at #=zNlI1$ziqDhgatrogOXJHTlo8CHk6zfYu8wsQolA=.#=zkDGAjs0vjozF(String #=zY1ngovA=, Int32 #=zdSpAOUU=, SecurityOptions #=zKYQPqxHVHoFh)at #=zNlI1$ziqDhgatrogOXJHTlo8CHk6zfYu8wsQolA=.#=zWF25pxBdmwgv(String #=zY1ngovA=, Int32 #=zdSpAOUU=, SecurityOptions #=zKYQPqxHVHoFh)at #=zNlI1$ziqDhgatrogOXJHTlo8CHk6zfYu8wsQolA=.#=zcLl$LsXtGRsn(String #=zY1ngovA=, Int32 #=zdSpAOUU=, IList1 #=zqbCPEbdNknR9) --- End of inner exception stack trace ---at #=zNlI1$ziqDhgatrogOXJHTlo8CHk6zfYu8wsQolA=.#=zcLl$LsXtGRsn(String #=zY1ngovA=, Int32 #=zdSpAOUU=, IList1 #=zqbCPEbdNknR9)at #=zNlI1$ziqDhgatrogOXJHTlo8CHk6zfYu8wsQolA=.#=zcLl$LsXtGRsn(String #=zY1ngovA=, Int32 #=zdSpAOUU=)at #=zNlI1$ziqDhgatrogOXJHTlo8CHk6zfYu8wsQolA=.#=zQUUHDII=()at #=zQvzlN1iF9eZnhdI2jRMo$aF2GiXKdlJbLg==.#=zNk7I5RohgB1h() — End of inner exception stack trace —at #=z9iSzmGr8Rv2NoVfjwFPLBDnkweR5.#=zGRdyl88=(IAsyncResult #=zoiuWW04=)at #=z9iSzmGr8Rv2NoVfjwFPLBDnkweR5.#=zXYpRvxI=()at #=z7wgpP2yA$Kf4Msm9KzV5DuG84KGnetcGc6QFaSI=.#=zuqERXhM=(#=zz$BIg_POcfoAdK9ejQ4JlmbEH4kP$irlYA== #=za6XAuHA=)at #=zy5$uBOqOuLvKCL3rFvZyAxKmMA9f.#=z05rAtRavEQuz(Int32 #=z0JMOilw=, #=zz$BIg_POcfoAdK9ejQ4JlmbEH4kP$irlYA== #=zzrMQxkc=)at #=zy5$uBOqOuLvKCL3rFvZyAxKmMA9f.#=zRC6oVsw=(Boolean #=z59mAARJNvKtF, #=zz$BIg_POcfoAdK9ejQ4JlmbEH4kP$irlYA== #=zzrMQxkc=)at Aspose.Email.Clients.EmailClient.CreateConnection(Boolean createAsDefaultConnection)

Code that I am using for creating SmtpClient

var client = new SmtpClient(“smtp.office365.com”, 587)
{
SecurityOptions = Settings.UseSsl ? SecurityOptions.SSLAuto : SecurityOptions.Auto,
UseAuthentication = true,
UseDefaultCredentials = false
};

Even tried by modifying the code to the below one, but got no benefit
var client = new SmtpClient(Settings.Host, Settings.Port)
{
SecurityOptions = Settings.UseSsl ? SecurityOptions.SSLAuto : SecurityOptions.Auto,
SupportedEncryption = EncryptionProtocols.Tls12 | EncryptionProtocols.Tls11 | EncryptionProtocols.Tls,
UseAuthentication = true,
UseDefaultCredentials = false
};

            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

@anmolsdna,
Thank you for the query. Please take a look at the code example below showing how to use OAuth 2.0 for a Google account:

    public class TokenResponse
    {
        [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "access_token", Required = Newtonsoft.Json.Required.Default)]
        public string AccessToken { get; set; }

        [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "token_type", Required = Newtonsoft.Json.Required.Default)]
        public string TokenType { get; set; }

        [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "expires_in", Required = Newtonsoft.Json.Required.Default)]
        public int ExpiresIn { get; set; }

        [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "refresh_token", Required = Newtonsoft.Json.Required.Default)]
        public string RefreshToken { get; set; }

        [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "scope", Required = Newtonsoft.Json.Required.Default)]
        public string Scope { get; set; }
    }

    /// <summary>
    /// Developers console
    /// https://console.cloud.google.com/projectselector2
    /// Documentation
    /// https://developers.google.com/identity/protocols/oauth2/native-app
    /// </summary>
    internal class GoogleOAuthHelper
    {
        public const string AUTHORIZATION_URL = "https://accounts.google.com/o/oauth2/v2/auth";
        //public const string TOKEN_REQUEST_URL = "https://www.googleapis.com/oauth2/v4/token";
        public const string TOKEN_REQUEST_URL = "https://oauth2.googleapis.com/token";
        public const string LOGOUT_URL = "https://accounts.google.com/Logout";
        public const string LOGIN_URL = "https://accounts.google.com/ServiceLogin";
        public static string codeVerifier;
        public static string codeChallenge;
        public static CodeChallengeMethod codeChallengeMethod = CodeChallengeMethod.S256;
        public const string SCOPE =
            "https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar" + // Calendar
            "+" +
            "https%3A%2F%2Fwww.google.com%2Fm8%2Ffeeds%2F" + // Contacts
            "+" +
            "https%3A%2F%2Fmail.google.com%2F"; // IMAP & SMTP
        public const string REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob";
        public const string REDIRECT_TYPE = "code";

        static GoogleOAuthHelper()
        {
            CreateCodeVerifier();
            CreateCodeChalange();
        }

        internal static string CreateCodeVerifier()
        {
            string allowedChars = "0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-._~";
            char[] chars = allowedChars.ToCharArray();
            int minLength = 43;
            int maxLength = 128;
            Random rnd = new Random();
            int length = minLength + rnd.Next(maxLength - minLength);
            List<char> codeVerifierChars = new List<char>();
            for (int i = 0; i < length; i++)
            {
                int index = rnd.Next(allowedChars.Length);
                codeVerifierChars.Add(allowedChars[index]);
            }
            return codeVerifier = string.Join("", codeVerifierChars.ToArray());
        }

        internal static string CreateCodeChalange()
        {
            if (codeChallengeMethod == CodeChallengeMethod.plain)
                return codeChallenge = codeVerifier;
            byte[] hashValue = null;
            using (SHA256 sha256 = SHA256.Create())
                hashValue = sha256.ComputeHash(Encoding.ASCII.GetBytes(codeVerifier));
            string b64 = Convert.ToBase64String(hashValue);
            b64 = b64.Split('=')[0];
            b64 = b64.Replace('+', '-');
            b64 = b64.Replace('/', '_');
            return codeChallenge = b64;
        }

        internal static string GetAuthorizationCodeUrl(TestUser acc)
        {
            return GetAuthorizationCodeUrl((OAuthTestUser)acc, SCOPE, REDIRECT_URI, REDIRECT_TYPE);
        }

        internal static string GetAuthorizationCodeUrlUrl(OAuthTestUser acc)
        {
            return GetAuthorizationCodeUrl(acc, SCOPE, REDIRECT_URI, REDIRECT_TYPE);
        }

        internal static string GetAuthorizationCodeUrlUrl(
             TestUser acc,
             string scope,
             string redirectUri,
             string responseType)
        {
            return GetAuthorizationCodeUrl(
                (OAuthTestUser)acc,
                scope,
                redirectUri,
                responseType);
        }

        internal static string GetAuthorizationCodeUrl(
            OAuthTestUser acc,
            string scope,
            string redirectUri,
            string responseType)
        {
            Debug.WriteLine("");
            Debug.WriteLine("---------------------------------------------------------");
            Debug.WriteLine("-----------OAuth 2.0 authorization information-----------");
            Debug.WriteLine("---------------------------------------------------------");
            Debug.WriteLine(string.Format("Login: '{0}'", acc.EMail));

            string state = System.Web.HttpUtility.UrlEncode(Guid.NewGuid().ToString());
            string authorizationCode = null;
            string error = null;
            string approveUrl = AUTHORIZATION_URL +
                $"?client_id={acc.ClientId}&redirect_uri={redirectUri}&response_type={responseType}&scope={scope}&" +
                $"code_challenge={codeChallenge}&code_challenge_method={codeChallengeMethod.ToString()}&" +
                $"state={state}"
                ;
            return approveUrl;
        }

        internal static TokenResponse GetAccessTokenByRefreshToken(TestUser user)
        {
            return GetAccessTokenByRefreshToken((OAuthTestUser)user);
        }

        internal static TokenResponse GetAccessTokenByRefreshToken(OAuthTestUser user)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(TOKEN_REQUEST_URL);
            request.CookieContainer = new CookieContainer();
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            var clientId = System.Web.HttpUtility.UrlEncode(user.ClientId);
            var clientSecret = System.Web.HttpUtility.UrlEncode(user.ClientSecret);
            var refreshToken = System.Web.HttpUtility.UrlEncode(user.RefreshToken);
            var grantType = System.Web.HttpUtility.UrlEncode(GrantTypes.refresh_token.ToString());

            string encodedParameters = $"client_id={clientId}&client_secret={clientSecret}&refresh_token={refreshToken}&grant_type={grantType}";

            byte[] requestData = Encoding.UTF8.GetBytes(encodedParameters);
            request.ContentLength = requestData.Length;
            if (requestData.Length > 0)
                using (Stream stream = request.GetRequestStream())
                    stream.Write(requestData, 0, requestData.Length);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            string responseText = null;
            using (TextReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
                responseText = reader.ReadToEnd();
            TokenResponse tokensResponse = JsonConvert.DeserializeObject<TokenResponse>(responseText);
            Debug.WriteLine("");
            Debug.WriteLine("---------------------------------------------------------");
            Debug.WriteLine("-----------OAuth 2.0 authorization information-----------");
            Debug.WriteLine("---------------------------------------------------------");
            Debug.WriteLine(string.Format("Login: '{0}'", user.EMail));
            Debug.WriteLine(string.Format("Access token: '{0}'", tokensResponse.AccessToken));
            Debug.WriteLine(string.Format("Token type: '{0}'", tokensResponse.TokenType));
            Debug.WriteLine(string.Format("Expires in: '{0}'", tokensResponse.ExpiresIn));
            Debug.WriteLine("---------------------------------------------------------");
            Debug.WriteLine("");
            return tokensResponse;
        }

        internal static TokenResponse GetAccessTokenByAuthCode(string authorizationCode, TestUser user)
        {
            return GetAccessTokenByAuthCode(authorizationCode, (OAuthTestUser)user);
        }

        internal static TokenResponse GetAccessTokenByAuthCode(string authorizationCode, OAuthTestUser user)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(TOKEN_REQUEST_URL);
            request.CookieContainer = new CookieContainer();
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            string clientId = System.Web.HttpUtility.UrlEncode(user.ClientId);
            string clientSecret = System.Web.HttpUtility.UrlEncode(user.ClientSecret);
            string authCode = System.Web.HttpUtility.UrlEncode(authorizationCode);
            string redirectUri = System.Web.HttpUtility.UrlEncode(REDIRECT_URI);
            string grantType = System.Web.HttpUtility.UrlEncode(GrantTypes.authorization_code.ToString());
            string encodedParameters = $"client_id={clientId}&client_secret={clientSecret}&code={authCode}&code_verifier={codeVerifier}&redirect_uri={redirectUri}&grant_type={grantType}";
            byte[] requestData = Encoding.UTF8.GetBytes(encodedParameters);
            request.ContentLength = requestData.Length;
            if (requestData.Length > 0)
                using (Stream stream = request.GetRequestStream())
                    stream.Write(requestData, 0, requestData.Length);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            string responseText = null;
            using (TextReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
                responseText = reader.ReadToEnd();
            TokenResponse tokensResponse = JsonConvert.DeserializeObject<TokenResponse>(responseText);

            Debug.WriteLine(string.Format("Authorization code: '{0}'", authorizationCode));
            Debug.WriteLine(string.Format("Access token: '{0}'", tokensResponse.AccessToken));
            Debug.WriteLine(string.Format("Refresh token: '{0}'", tokensResponse.RefreshToken));
            Debug.WriteLine(string.Format("Token type: '{0}'", tokensResponse.TokenType));
            Debug.WriteLine(string.Format("Expires in: '{0}'", tokensResponse.ExpiresIn));
            Debug.WriteLine("---------------------------------------------------------");
            Debug.WriteLine("");
            return tokensResponse;
        }
    }

GoogleOAuthHelper has to be used in the next way:

// The first user has to generate an authorization code URL.
string authUrl = GoogleOAuthHelper.GetAuthorizationCodeUrl(user);
// Then he has to open this url in browser and complete all operations.
// As result he will get authorization code.
// User has to use this authorization code to retrieve refresh token (TokenResponse.RefreshToken)
string authorizationCode = "put your authorization code here";
TokenResponse tokenInfo = GoogleOAuthHelper.GetAccessTokenByAuthCode(authorizationCode, user);
// When refresh token exists, user may use it to retrieve access token
tokenInfo = GoogleOAuthHelper.GetAccessTokenByRefreshToken(user);

SMTP connection:

// The first way
string accessToken = GoogleOAuthHelper.GetAccessTokenByRefreshToken(user).AccessToken;

SmtpClient client = new SmtpClient(
    server.ImapUrl,
    server.ImapPort,
    user.EMail,
    accessToken,
    true,
    SecurityOptions.SSLImplicit);
// The second way
ITokenProvider tokenProvider = TokenProvider.Google.GetInstance(
    user.ClientId,
    user.ClientSecret,
    user.RefreshToken);

SmtpClient client = new SmtpClient(
    server.ImapUrl,
    server.ImapPort,
    user.EMail,
    tokenProvider,
    server.ImapSecurityOptions);

More details: Gmail Utility Features

You can do it for Office 365 account in a similar way.

Thank you Andrey for reply. But actually as I mentioned the my code works fine with office 365 account but on my local machine. Only on server I get this error. So issue is more of security.

@anmolsdna,
To investigate this case further, please share and specify the following:

  • your standalone comprehensive code example using OAuth 2.0
  • a description of your server environment

It would be great if you could provide credentials to check the issue on our side.

I will do the needful. But for the server environment, it would be great if you can highlight the key information that I should provide you in regards to this security issue.

@anmolsdna,
I logged the issue in our tracking system with ID EMAILNET-40245. I will let you know later what additional information regarding the security issue you should provide.

Hi @Andrey_Potapov
Following are my server details do let me know if you need any other information in addition to the below one:-

Windows Server 2016 Datacenter
Protocols enabled are
TLS - 1.0,1.1,1.2
SSL - 2.0,3.0
PCT 1.0

All Ciphers,hashes are enabled

.net framework version being used is 4.7.2
aspose version being used is 21.4

@anmolsdna,
Thank you for the additional information.

We are still waiting for the standalone comprehensive code example using OAuth 2.0 from you that can be used for reproducing the error.

@Andrey_Potapov
Sharing you sample code… I am using dll of this project in my web application…So providing you the same…

You need to debug the test case with the name SendMailsWithMicrosoftOAuth in class SmtpClientTest.cs

As already shared the security related code is in SmtpMailClient.cs line number 128 in which security options are being set…

I have already shared this security code snippet earlier. As said the same code works fine on local machine but not on windows server 2016 datacenter. So it is more of a security issue…rest you can have a look to the code…

@anmolsdna,
Thank you for the code sample. I passed it to our development team.

@Andrey_Potapov any update on this one. As we are stuck in completing the development

@anmolsdna,
I requested an estimated time to fix this issue from our development team. I will let you know as soon as possible.

@anmolsdna,
Our development team will investigate the issue this week. If a bug is found, it will be fixed in the next release.

@anmolsdna,
Unfortunately, our development team has not managed to reproduce the error in the same environment (Windows Server 2016 Datacenter).
Please try to do the following:

  1. Check the issue with the latest version of Aspose.Email.
  2. Enable logging, start the application with the error, and send us a log file.
  3. Set SecurityOptions.SSLExplicit for the client, start the application with logging and if the error occurs in this case, send us the log file.

I will do the needful and will revert

@Andrey_Potapov

I added app.config but the log file is not getting generated.
You can use the same sample code just upgrade it to 21.5, Set the below setting in SmtpMailClient.cs file
SecurityOptions.SSLExplicit //line number 148.

Rest will update you…

@anmolsdna,
I passed your information to our development team. I will inform you of any progress.

@anmolsdna,
Did you try to do 1 and 3 actions without logging on your side?

@Andrey_Potapov
Yes, following things I did at my side once you shared the 3 steps

  1. Did all the 3 steps in code sample
    OUTPUT: smtp unit test case works fine, but after giving wrong credentials or settings no logs generated
  2. Same modification done in my dll project.
    OUTPUT: smtp unit test case works fine, but after giving wrong credentials or settings no logs generated
  3. Give reference of my dll project to my .net application after doing the 3 steps
    OUTPUT
    1. On local as well as on server machine I get the below error in catch, but no log generated

An error occured while connecting SmtpClient: AsposeException: Could not load file or assembly ‘Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed’ or one of its dependencies. The system cannot find the file specified.—> System.IO.FileNotFoundException: Could not load file or assembly ‘Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed’ or one of its dependencies. The system cannot find the file specified. File name: 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed’at IdentityModel.Client.ProtocolResponse.d__01.MoveNext()at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.Start[TStateMachine](TStateMachine& stateMachine)at IdentityModel.Client.ProtocolResponse.FromHttpResponseAsync[T](HttpResponseMessage httpResponse, Object initializationData)at IdentityModel.Client.HttpClientTokenRequestExtensions.d__8.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)at IdentityModel.Client.HttpClientTokenRequestExtensions.d__2.MoveNext() — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()at Onguard.Email.Exchange.AzureTokenProvider.<GetAccessTokenAsync>d__11.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()at Onguard.Email.Exchange.AzureTokenProvider.GetAccessToken(Boolean ignoreExistingToken)at #=zymdEgzfzjZx9qeCvDAGNgbsE0JoZj9zj2w==.#=ztt_1rJA=(String #=z3Qmxo0c=, ITokenProvider #=zkCWRhMw=)at #=zymdEgzfzjZx9qeCvDAGNgbsE0JoZj9zj2w==.#=zM3izurY=(String #=zW92_sds=, NetworkCredential #=zmyV$tpY=, Object #=zAorLCsaG547s)at #=zebNWMvvliJnbtk7Zm3EtgHuv4jVlommmI_MDj0k=.#=zof9xNp0hieUR(#=zK30BhX_PFQiGJGTPi7hs1D$9AIHJ3$l5RA== #=zkDPz_vQ=, NetworkCredential #=zNNlOd$I=)at #=zebNWMvvliJnbtk7Zm3EtgHuv4jVlommmI_MDj0k=.#=zOlH1ecdwtIiAmDaUlCnqOEs=(String #=zhZHrju8=, Int32 #=znxd$uNI=)at #=zebNWMvvliJnbtk7Zm3EtgHuv4jVlommmI_MDj0k=.#=zGZLwRJDNFos7(String #=zhZHrju8=, Int32 #=znxd$uNI=, SecurityOptions #=zq0B2vLhmyob5)at #=zebNWMvvliJnbtk7Zm3EtgHuv4jVlommmI_MDj0k=.#=z8u8H8yH2t29F(String #=zhZHrju8=, Int32 #=znxd$uNI=, IList`1 #=zP29groQzTII7) WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. — End of inner exception stack trace —at #=zirNI$9FSMqK4aNokyUKKMxcZXW1c.#=zsutwAyw=(IAsyncResult #=zX09FF5g=)at #=zirNI$9FSMqK4aNokyUKKMxcZXW1c.#=zA7pbz20=()at #=zj0Jow2BXKanIAGAs4VvDFyq5lVbYVVZ8yJW1sho=.#=z$mnlql0=(#=zxkLbMQAqxHJE1UZtXp_OHaP4IuVeQVgNfA== #=zgjePO0Q=)at #=zu$FnsJBaomaGGgGs$h2dPwP9seOK.#=zTvT7iLyTkTZY(Int32 #=zprRLj1A=, #=zxkLbMQAqxHJE1UZtXp_OHaP4IuVeQVgNfA== #=zDAqc4xw=)at #=zu$FnsJBaomaGGgGs$h2dPwP9seOK.#=z5XHQvNs=(Boolean #=zOgGwN1pLkKsv, #=zxkLbMQAqxHJE1UZtXp_OHaP4IuVeQVgNfA== #=zDAqc4xw=)at Aspose.Email.Clients.EmailClient.CreateConnection(Boolean createAsDefaultConnection)at Onguard.Email.Clients.SmtpMailClient.ConnectAsync() 06/18/2021 20:02:26 Error : Connection can not be established for setting UUID 123.

@anmolsdna,
Did I understand correctly that after updating Aspose.Email to the latest version, enabling logging and applying SecurityOptions.SSLExplicit, you get the AsposeException?