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

I m using the below code when exception come then mail send successfully, but when no exception then invalid length for a base-64 char array. Pleas reply me...

C#
public void UpdateData()
{ 
  try
   {
     sendMail(UpdateData());//here message is success
   }
   Catch(Exception ex)
   {
   sendMail(ex.Message)

   }
}
public void sendMail(string strExceptionMsg)
{
MailMessage objMailMessage = null;
SmtpClient SmtpMail = null;
System.IO.StreamWriter Log=null;
try
  {
using ( Log Log = new System.IO.StreamWriter(apppath + "\\ImportLogMail.txt", true))
  {
    Log.WriteLine(DateTime.Now.ToString() + "Start Sending Email.......");
                 objMailMessage = new MailMessage();
                 objMailMessage.To.Add(MailTo);
                 objMailMessage.From = new MailAddress(MailFrom);
                 if (resultId == 0)
                   {
                    objMailMessage.IsBodyHtml = false;
                    objMailMessage.Subject = "Branch Code Update Status";
                     if (isValidTextFile)
                        {
                     objMailMessage.Body = "Hi" + Environment.NewLine + "Please  find the attached text file for log information.";
                        }
                        else
                        {
                   objMailMessage.Body = "The file:" + fileName + " content of the file was not correct format";
                        }
                  Attachment attach = new Attachment(apppath + "\\ImportLog.txt");
                  objMailMessage.Attachments.Add(attach);
                    }

                    else
                    {
                        objMailMessage.IsBodyHtml = false;
                        objMailMessage.Subject = "Branch Code Update Status -Exception";
                  objMailMessage.Body = "Hi" + Environment.NewLine + "The following error occured while running the project." + Environment.NewLine + strExceptionMsg;
                    }

                    SmtpMail = new SmtpClient();
                    SmtpMail.Host = SMTPHost;
                    SmtpMail.Port = Convert.ToInt32(SMTPPort);
                    //SmtpMail.Timeout = 50000;
                    SmtpMail.EnableSsl = false;
                    SmtpMail.Credentials = new System.Net.NetworkCredential(SMTPUserId, SMTPPassword);
                    SmtpMail.UseDefaultCredentials = true;

                    SmtpMail.Send(objMailMessage);
                Log.WriteLine(DateTime.Now.ToString() + "End Sending Email.......");

                                                                                                
                
            }
            catch (SmtpException ex)
            {
       Log.WriteLine(ex.message);        }
Posted
Updated 22-Mar-12 16:50pm
v2
Comments
[no name] 22-Mar-12 22:52pm    
What? Out of the thousands of errors that you can get you expect to guess what error you are getting? On top of guessing which line of code you are getting an error on?

Yes we can read your mind.
Sergey Alexandrovich Kryukov 22-Mar-12 23:12pm    
My mind reader is in the service shop right now. And my access to OP's hard drive is limited during spring season, so I'm sorry to say, I hardly can help much. :-)
--SA
laxman B 22-Mar-12 23:00pm    
I forgot to change this one, now working fine....
SmtpMail.UseDefaultCredentials = false;
Ganesan Senthilvel 23-Mar-12 1:29am    
good catch laxman

1 solution

Answered to remove from unanswered list - solved by OP.
 
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