468,469 Members | 1,618 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,469 developers. It's quick & easy.

Error sending SMTP MAil message in c#

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
2 11757

"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
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.

Similar topics

4 posts views Thread by z f | last post: by
3 posts views Thread by dgiagio | last post: by
11 posts views Thread by hazz | last post: by
3 posts views Thread by Ibrahim. | last post: by
6 posts views Thread by Dave Kelly | last post: by
5 posts views Thread by Don Quijote de Nicaragua | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.