title: Mandrill API response with HTTP Status 500
body: <p>I've been trying to get my MVC web app to send emails using a subscription with Mandrill API to no avail. This Mandrill API works by POSTing a <code>JSON</code> object to a specific endpoint. It looks pretty simple and straight-forward and that's why it's so frustrating that everytime I tried to send an email message I get an response from Mandrill with nothing more than a "500 Internal Server Error" no extra information or anything else.</p>
  
  <p>Interestingly, Mandrill API has a <a href="https://mandrillapp.com/api/docs/messages.JSON.html" rel="nofollow">public test tool</a> that you can use to test their API. So, I went in and passed exactly the same <code>JSON</code> object my application is sending when receiving that annoying Http Error and the email message is sent without any issues. So basically I have no problems sending the same email through their <a href="https://mandrillapp.com/api/docs/messages.JSON.html" rel="nofollow">Test Tool</a> but it fails when my application attempts to send it.</p>
  
  <p>Please find below the delegated to send the email message. It's not yet re-factored...sorry...</p>
  
  <pre><code>public bool Send(string to, string toDisplayName, string subject, string body)
  {
          var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://mandrillapp.com/api/1.0/messages/send.json");
          httpWebRequest.ContentType = "text/json";
          httpWebRequest.Method = "POST";
  
          try
          {
              using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
              {
                  string json = string.Format(@"{{""key"": ""{0}"",""message"": {{""html"": ""{1}"",""subject"": ""{2}"",""from_email"": ""{3}"",""from_name"": ""AppCompear"",""to"": [{{""email"": ""{4}"",""name"": ""{5}"",""type"": ""to""}}],""important"": false}},""async"": false,""ip_pool"": ""Main Pool""}}"
                      , _setting.Password, body.Replace(@"""", @"\"""), subject, _setting.UserName, to, toDisplayName);
  
                  LogManager.Current.LogError(to, "", "", "", null, json);
                  streamWriter.Write(json);
                  streamWriter.Flush();
                  streamWriter.Close();
  
                  var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                  using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                  {
                      var result = streamReader.ReadToEnd();
                  }
              }
          }
          catch (WebException wex)
          {
              LogManager.Current.LogError(to, "", "", "", wex, wex.Message);
          }
          catch (Exception ex)
          {
              LogManager.Current.LogError(to, "", "", "", ex, ex.Message);
          }
  
          return true;
    }
  </code></pre>
  
  <p>And of course, it fails when trying to get the response</p>
  
  <pre><code>var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  </code></pre>
  
  <p>Any help will be greatly appreciated</p>