Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

Hi Guys,

I'm using the .net SMTP classes to send emails out to clients,I've been using it for over 2 years without any problems.We have now switced over to a new email host and for some reason I get the following error when trying to send an email.

Failure sending mail.

System.FormatException: Invalid length for a Base-64 char array.
at System.Convert.FromBase64String(String s)
at System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob)
at System.Net.Mail.SmtpNtlmAuthenticationModule.Authenticate(String challenge, NetworkCredential credential, Object sessionCookie)

Any ideas what might be causing this problem ?  I'm only parsing the host name,port number,username and password.All values are string except of course for the port which is an int.

Using Visual C# 2.0.

Thanks in advance for all help.

Posted

Hi

Does this problem persist everytime or only from time to time?

 
Share this answer
 

Hey Guys,

 

I found a solution on the following link

http://blogs.msdn.com/knom/archive/2008/04/16/hacking-system-net-mail-smtpclient.aspx 

 

Seems to be the underlaying authentication modules  in the smtpClient that would be default use NTLM,by using reflection you can "override" the values.

 

 

 // Example in specified link

FieldInfo transport = _client.GetType().GetField("transport", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo authModules = transport.GetValue(_client).GetType() .GetField("authenticationModules", BindingFlags.NonPublic | BindingFlags.Instance);

Array modulesArray = authModules.GetValue(transport.GetValue(_client)) as Array; modulesArray.SetValue(modulesArray.GetValue(2), 0); modulesArray.SetValue(modulesArray.GetValue(2), 1); modulesArray.SetValue(modulesArray.GetValue(2), 3);

 

In my code I did all the above,only difference is that I only replaced element number 1 in the array and made the value the same as the value in element 3 which would be "Login".This worked for me and I hope it will help someone else with the same problem that was not as lucky as to stumble on to the link.

// What I did in my code 

 modulesArray.SetValue(modulesArray.GetValue(3), 1);

 

Kind Regards,

FREDDIE.

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900