title: Bad Request error using SendGrid SMTP email submission
body: <p>I am currently using C# in MVC4 ASP.NET 4.5.</p>
  
  <p>My application creates a user and then submits a registration email to that use to authenticate their email. To create this script, I followed this tutorial: <a href="http://www.windowsazure.com/en-us/documentation/articles/sendgrid-dotnet-how-to-send-email/" rel="nofollow noreferrer">How to Send Email Using SendGrid with Windows Azure</a></p>
  
  <p>I am using the latest version of <a href="http://www.nuget.org/packages/Sendgrid/" rel="nofollow noreferrer">SendGrid (2.1.1)</a></p>
  
  <p>Code specific namespaces being used:</p>
  
  <pre><code>using SendGridMail;
  using System.Net;
  using System.Net.Mail;
  </code></pre>
  
  <p>Here is my code that creates the SendGrid mail message:</p>
  
  <pre><code>SendGrid message = SendGrid.GetInstance();
  message.From = new MailAddress(fromEmail); //fromEmail is a MailAddress type
  message.AddTo(userName); //this is a string
  message.Html = body; //this is also a string
  </code></pre>
  
  <p>Then I go to send the email:</p>
  
  <pre><code>//Create login info for email
  NetworkCredential credentials = new NetworkCredential("username", "password");
  var trasnportSMTP = Web.GetInstance(credentials);
  trasnportSMTP.Deliver(message); //smtp.sendgrid.net Send message
  </code></pre>
  
  <p>On the last line where "trasnportSMTP.Deliver(message);" I get this error:</p>
  
  <blockquote>
    <p>Server Error in '/' Application.</p>
    
    <p><strong>Bad Request</strong></p>
    
    <p><strong>Description:</strong> An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more
    information about the error and where it originated in the code. </p>
    
    <p><strong>Exception Details:</strong> System.Exception: Bad Request</p>
  </blockquote>
  
  <p><strong>The only things I've noticed while tracing is in the Exception Snapshot in View Details and the Output window.</strong> </p>
  
  <p>I noticed that the: 
  TargetSite = {Void CheckForErrors(System.Net.Http.HttpResponseMessage)}, 
  ReturnType is {Name = "Void" FullName = "System.Void"}, 
  ReflectedType is {Name = "Web" FullName = "SendGridMail.Web"}, 
  CustomAttributes - Count = 0, 
  Name = "CheckForErrors", 
  It's in the Module {SendGridMail.dll}. </p>
  
  <p>Also in my output, there is the following: </p>
  
  <blockquote>
    <p>"A first chance exception of type <code>'System.FormatException'</code> occurred
    in System.dll Step into: Stepping over non-user code
    <code>'SendGridMail.Web.Deliver'</code>"</p>
  </blockquote>
  
  <p>Can anyone give me some more insight on why this error is happening. I am using the correct username and password that is on the SendGrid account on Azure.</p>
  
  <p>Thank you ahead of time.</p>