473,385 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 12118

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: z f | last post by:
Hi, i'm sending mail from the aspx page on the server. it is running on hosting, so i configure the System.Web.Mail.SmtpMail.SmtpServer property to my mail server. but problem is that sender...
9
by: B-Dog | last post by:
I've built a small app that sends mail through our ISP's SMTP server but when I try to send through my local exchange server I get CDO error. Does webmail use SMTP or does it strictly rely on...
3
by: dgiagio | last post by:
Hi, I'm creating a SMTP application and I would like to hear opinions about error handling. Currently there are two functions that communicate with the remote peer: ssize_t...
14
by: supz | last post by:
Hi, I use the standard code given below to send an email from an ASP.NET web form. The code executes fine but no Email is sent. All emails get queued in the Inetpub mail queue. I'm using my...
11
by: hazz | last post by:
smtpClient.Send(message) is causing me problems as per specifics in the trace below. Email is sent but not without this error typically upon sending the second email, but sometimes when running...
3
by: Ibrahim. | last post by:
Hello, Im getting the following error when mail is sent from ASP.NET 2.0 website. CDO.Messaging componenet is used for sending mail. " The message was not able to be transmitted to the SMTP...
2
by: satnamsarai | last post by:
Using System.Net.Mail: Sometimes I get error 'failure sending mail. Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.' Not sure how...
6
by: Dave Kelly | last post by:
Sorry for the long post, it is easier to discard information than to have to wait for it to arrive. So here goes: This code worked perfectly when I was an Earthlink customer. Sprint decided...
5
by: Don Quijote de Nicaragua | last post by:
Hi, everyone I try to send a simple e-mail witch this Code, but always send me a error messages: "ERROR: Failure sending mail." Thansk You. Don Quijote de Nicaragua. Elder Soto. Dim correo As...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.