By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,208 Members | 1,072 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,208 IT Pros & Developers. It's quick & easy.

Error sending SMTP MAil message in c#

P: n/a
HI All,

I am encountering the following error when I try to send an email through a
SMTP server. I believe the problem lies with the authentication part when the
network crednetials are used, error is thrown at the .send point.

Error is:
The following error occured Sending an email: System.ApplicationException:
An error occurred sending an email To he***@HerMail.com
From ad*@MyMail.com Cc Subject A test with Finlistener #1. The body was:
This is test for the body of the error email --->
System.Net.Mail.SmtpException: 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.Authe nticate(String
challenge, NetworkCredential credential, Object sessionCookie)
at System.Net.Mail.SmtpConnection.GetConnection(Strin g host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
--
The code looks like:
MailMessage Message = new MailMessage();
string[] AddressList;
AddressList = To.Split(Convert.ToChar(";"));
// To list
for (int i = 0; i <= AddressList.GetUpperBound(0); i++)
{
if (AddressList[i] != string.Empty)
{Message.To.Add(AddressList[i]);}
}
// CC list
AddressList = CC.Split(Convert.ToChar(";"));
for (int i = 0; i <= AddressList.GetUpperBound(0); i++)
{
if (AddressList[i] != string.Empty)
{Message.CC.Add(AddressList[i]);}
}

Message.Subject = Subject;
Message.SubjectEncoding = System.Text.Encoding.UTF8;
Message.From = new
MailAddress(_From,"Finlistener",System.Text.Encodi ng.UTF8);
Message.Body = Body;
Message.BodyEncoding = System.Text.Encoding.UTF8;
Message.IsBodyHtml = false;
SmtpClient SMTP = new SmtpClient(_SMTPServer,25);
if (_UserName != string.Empty)
{
SMTP.Credentials = new
System.Net.NetworkCredential(_UserName, _Password);
SMTP.DeliveryMethod = SmtpDeliveryMethod.Network;
}
SMTP.Send(Message);
Big thank you for your help.
Jul 2 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Ade" <ad*@nospam.nospamwrote in message
news:F4**********************************@microsof t.com...
HI All,

I am encountering the following error when I try to send an email through
a
SMTP server. I believe the problem lies with the authentication part when
the
network crednetials are used, error is thrown at the .send point.

Error is:
The following error occured Sending an email: System.ApplicationException:
An error occurred sending an email To he***@HerMail.com
From ad*@MyMail.com Cc Subject A test with Finlistener #1. The body was:
This is test for the body of the error email --->
System.Net.Mail.SmtpException: 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.Authe nticate(String
challenge, NetworkCredential credential, Object sessionCookie)
at System.Net.Mail.SmtpConnection.GetConnection(Strin g host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
--
The code looks like:
MailMessage Message = new MailMessage();
string[] AddressList;
AddressList = To.Split(Convert.ToChar(";"));
// To list
for (int i = 0; i <= AddressList.GetUpperBound(0); i++)
{
if (AddressList[i] != string.Empty)
{Message.To.Add(AddressList[i]);}
}
// CC list
AddressList = CC.Split(Convert.ToChar(";"));
for (int i = 0; i <= AddressList.GetUpperBound(0); i++)
{
if (AddressList[i] != string.Empty)
{Message.CC.Add(AddressList[i]);}
}

Message.Subject = Subject;
Message.SubjectEncoding = System.Text.Encoding.UTF8;
Message.From = new
MailAddress(_From,"Finlistener",System.Text.Encodi ng.UTF8);
Message.Body = Body;
Message.BodyEncoding = System.Text.Encoding.UTF8;
Message.IsBodyHtml = false;
SmtpClient SMTP = new SmtpClient(_SMTPServer,25);
if (_UserName != string.Empty)
{
SMTP.Credentials = new
System.Net.NetworkCredential(_UserName, _Password);
SMTP.DeliveryMethod = SmtpDeliveryMethod.Network;
}
SMTP.Send(Message);
Big thank you for your help.
Obviously, it doesn't like that array in middle of the routine. You need to
pull it out and do that somewhere else and populate it in a string variable
using a stringbuilder or something, having it already populated and ready to
use before you get there.
..

Jul 2 '07 #2

P: n/a
HI Mr Arnold,

Thanks for taking the time to look at my problem. I have re-done the code as
follows, but I get the same error.

MailMessage Message = new MailMessage();
Message.To.Add(new
MailAddress("he***@HerMail.com","Helen",System.Tex t.Encoding.UTF8));
Message.Subject = Subject;
Message.SubjectEncoding = System.Text.Encoding.UTF8;
Message.From = new
MailAddress(_From,"Finlistener",System.Text.Encodi ng.UTF8);
Message.Body = Body;
Message.BodyEncoding = System.Text.Encoding.UTF8;
Message.IsBodyHtml = false;
SmtpClient SMTP = new SmtpClient(_SMTPServer,25);
if (_UserName != string.Empty)
{
SMTP.Credentials = new
System.Net.NetworkCredential(_UserName, _Password);
SMTP.DeliveryMethod = SmtpDeliveryMethod.Network;
}
SMTP.Send(Message);
--

Is this what you meant by your last post?
Big thank you for your help.
"Mr. Arnold" wrote:
>
"Ade" <ad*@nospam.nospamwrote in message
news:F4**********************************@microsof t.com...
HI All,

I am encountering the following error when I try to send an email through
a
SMTP server. I believe the problem lies with the authentication part when
the
network crednetials are used, error is thrown at the .send point.

Error is:
The following error occured Sending an email: System.ApplicationException:
An error occurred sending an email To he***@HerMail.com
From ad*@MyMail.com Cc Subject A test with Finlistener #1. The body was:
This is test for the body of the error email --->
System.Net.Mail.SmtpException: 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.Authe nticate(String
challenge, NetworkCredential credential, Object sessionCookie)
at System.Net.Mail.SmtpConnection.GetConnection(Strin g host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
--
The code looks like:
MailMessage Message = new MailMessage();
string[] AddressList;
AddressList = To.Split(Convert.ToChar(";"));
// To list
for (int i = 0; i <= AddressList.GetUpperBound(0); i++)
{
if (AddressList[i] != string.Empty)
{Message.To.Add(AddressList[i]);}
}
// CC list
AddressList = CC.Split(Convert.ToChar(";"));
for (int i = 0; i <= AddressList.GetUpperBound(0); i++)
{
if (AddressList[i] != string.Empty)
{Message.CC.Add(AddressList[i]);}
}

Message.Subject = Subject;
Message.SubjectEncoding = System.Text.Encoding.UTF8;
Message.From = new
MailAddress(_From,"Finlistener",System.Text.Encodi ng.UTF8);
Message.Body = Body;
Message.BodyEncoding = System.Text.Encoding.UTF8;
Message.IsBodyHtml = false;
SmtpClient SMTP = new SmtpClient(_SMTPServer,25);
if (_UserName != string.Empty)
{
SMTP.Credentials = new
System.Net.NetworkCredential(_UserName, _Password);
SMTP.DeliveryMethod = SmtpDeliveryMethod.Network;
}
SMTP.Send(Message);
Big thank you for your help.

Obviously, it doesn't like that array in middle of the routine. You need to
pull it out and do that somewhere else and populate it in a string variable
using a stringbuilder or something, having it already populated and ready to
use before you get there.
..

Jul 2 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.