Showing posts with label Error Codes. Show all posts
Showing posts with label Error Codes. Show all posts

Saturday, March 23, 2013

SMTP Server Error: Bad sequence of commands. The server response was: you must authenticate first (#5.5.1)

This error occurs due to lock down of default mail server (127.0.0.1) by web hosting companies due to SPAM or what ever other security reasons. But if you use “localhost” or default server “127.0.0.1” on your local machine it should not be an issue. But if you have a situation where you need to relay e-mail to a remote mail server that is secured you get this exception.

So you need to handle well using built in classes provided by .NET. This is take care by NetworkCredential Class. This class provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication.

Here is a fully working quick code sample that you can use to get started on your own SMTP-Authentication supporting e-mail code.

   1: try
   2: {
   3:     SmtpClient smtpclient = new SmtpClient();
   4:     NetworkCredential NetworkCredential = new NetworkCredential(smtpUserName, smtpPassword);
   5:     smtpclient.Credentials = NetworkCredential;
   6:     string MailServer = ConfigurationManager.AppSettings["SMTPServer"].ToString();
   7:     MailMessage objEmail = new MailMessage();
   8:  
   9:     string FromEmail = ConfigurationManager.AppSettings["ErrorReportEmailFrom"].ToString();
  10:     if (FromEmail.IndexOf(";") > 0)
  11:     {
  12:         FromEmail = FromEmail.Replace(";", ",");
  13:     }
  14:     MailAddress FromAddress = new MailAddress(FromEmail);
  15:     objEmail.From = FromAddress;
  16:  
  17:     string ToEmail = ConfigurationManager.AppSettings["ErrorReportEmailTo"].ToString();
  18:     if (ToEmail.IndexOf(";") > 0)
  19:     {
  20:         ToEmail = ToEmail.Replace(";", ",");
  21:     }
  22:     objEmail.To.Add(ToEmail);
  23:  
  24:     string CcEmail = ConfigurationManager.AppSettings["CcEmail"].ToString();
  25:     if (CcEmail.IndexOf(";") > 0)
  26:     {
  27:         CcEmail = CcEmail.Replace(";", ",");
  28:     }
  29:     objEmail.CC.Add(CcEmail);
  30:  
  31:     string BccEmail = ConfigurationManager.AppSettings["BccEmail"].ToString();
  32:     if (BccEmail.IndexOf(";") > 0)
  33:     {
  34:         BccEmail = BccEmail.Replace(";", ",");
  35:     }
  36:     objEmail.Bcc.Add(BccEmail);
  37:  
  38:     objEmail.Subject = strSubject;
  39:     try
  40:     {
  41:         objEmail.Body = strBody;
  42:         objEmail.IsBodyHtml = true;
  43:         smtpclient.Host = MailServer;
  44:         smtpclient.Send(objEmail);
  45:     }
  46:     catch (Exception ex)
  47:     {
  48:         throw ex;
  49:     }
  50:     finally
  51:     {
  52:         objEmail.Dispose();
  53:     }
  54: }
  55: catch (Exception ex)
  56: {
  57:      
  58: }

Enjoy coding!!

Thursday, December 30, 2010

Silverlight Programming : “Operation not supported on read-only collection”

Recently when I was trying to bind data to a Combo box conditionally I got this message saying "Operation not supported on read-only collection". Though I am clearing items in the collection and binding the ItemsSource I got this error. So I have set ItemSource to null before I clear the items. It worked well for me. Here is the sample snippet for doing this.

CarrierAccountDropDownList.ItemsSource = null;
CarrierAccountDropDownList.Items.Clear();
CarrierAccountDropDownList.ItemsSource = e.Result;
Happy Coding Coffee cup

Wednesday, December 15, 2010

“CleanRiaClientFilesTask" task failed unexpectedly

Recently few of our developers and me got this error while building my Silverlight application. I got this error while checking in the code and merge my code changes.

Error Details.

Error    38    The "CleanRiaClientFilesTask" task failed unexpectedly.
System.ArgumentException: Illegal characters in path.

To resolve this we need to do two simple steps.

Step 1: Go to this location in your system or your Framework install directory, for me its C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files. Clean all the temporary files under this location and leave the root folder empty.

Step 2: Go to your project location and Delete all the files in \obj folder. Basically all the files are stored in the \obj folder created by ria services.

Now clean the project and try building again. It worked for me. Hope this will help you. Good luck Hot smile