Error sending SMTP MAil message in c#

G

Guest

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 (e-mail address removed)
From (e-mail address removed) 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.Authenticate(String
challenge, NetworkCredential credential, Object sessionCookie)
at System.Net.Mail.SmtpConnection.GetConnection(String 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 != string.Empty)
{Message.To.Add(AddressList);}
}
// CC list
AddressList = CC.Split(Convert.ToChar(";"));
for (int i = 0; i <= AddressList.GetUpperBound(0); i++)
{
if (AddressList != string.Empty)
{Message.CC.Add(AddressList);}
}

Message.Subject = Subject;
Message.SubjectEncoding = System.Text.Encoding.UTF8;
Message.From = new
MailAddress(_From,"Finlistener",System.Text.Encoding.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.
 
M

Mr. Arnold

Ade said:
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 (e-mail address removed)
From (e-mail address removed) 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.Authenticate(String
challenge, NetworkCredential credential, Object sessionCookie)
at System.Net.Mail.SmtpConnection.GetConnection(String 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 != string.Empty)
{Message.To.Add(AddressList);}
}
// CC list
AddressList = CC.Split(Convert.ToChar(";"));
for (int i = 0; i <= AddressList.GetUpperBound(0); i++)
{
if (AddressList != string.Empty)
{Message.CC.Add(AddressList);}
}

Message.Subject = Subject;
Message.SubjectEncoding = System.Text.Encoding.UTF8;
Message.From = new
MailAddress(_From,"Finlistener",System.Text.Encoding.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.
..
 
G

Guest

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("(e-mail address removed)","Helen",System.Text.Encoding.UTF8));
Message.Subject = Subject;
Message.SubjectEncoding = System.Text.Encoding.UTF8;
Message.From = new
MailAddress(_From,"Finlistener",System.Text.Encoding.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 said:
Ade said:
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 (e-mail address removed)
From (e-mail address removed) 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.Authenticate(String
challenge, NetworkCredential credential, Object sessionCookie)
at System.Net.Mail.SmtpConnection.GetConnection(String 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 != string.Empty)
{Message.To.Add(AddressList);}
}
// CC list
AddressList = CC.Split(Convert.ToChar(";"));
for (int i = 0; i <= AddressList.GetUpperBound(0); i++)
{
if (AddressList != string.Empty)
{Message.CC.Add(AddressList);}
}

Message.Subject = Subject;
Message.SubjectEncoding = System.Text.Encoding.UTF8;
Message.From = new
MailAddress(_From,"Finlistener",System.Text.Encoding.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.
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top