山钻:远程服务器返回错误:(500) 内部服务器错误



我正在使用下面的代码通过Mandrill发送邮件

    public bool sendMessage(string from, List<To> to, string subject, string body,out string rsText)
    {
        var host = "https://mandrillapp.com/api/1.0";
        if (key == "")
        {
            throw new Exception("No key provided");
        }
        bool b = false;
        System.Net.WebClient client = new System.Net.WebClient();
        client.Headers.Add("content-type", "application/json");
        MandrillMessage msg = new MandrillMessage()
        {
            from_email = from,
            html = body,
            to = to,
            subject = subject
        };
        this.message = msg;
        var jsonMsg = Newtonsoft.Json.JsonConvert.SerializeObject(this);
        var rs = client.UploadData(host + "/messages/send.json", "POST", System.Text.Encoding.Default.GetBytes(jsonMsg));
        var responseText = System.Text.Encoding.ASCII.GetString(rs);
        //TODO Reponse With Generic Class
        if (responseText.Contains("sent"))
        {
            b = true;
        }
        rsText = responseText;
        return b;
    }
}

当我调用上传数据方法时,我有一个例外:

"远程服务器返回错误: (500) 内部服务器错误。"

json 对象包含以下值

{"key":"aW1KVbcpVIQpPoSQgDkZ_Q","message":{"html":"\r\n\t\t                    <table style=\"border:0;color:#868789;font-family: verdana;\">\r\n\t\t                        <tr>\r\n\t\t                            <td rowspan=\"3\" style=\"vertical-align:middle;height:1083px;\" id=\"imagePrincipale\">\r\n\t\t                                <img src=\"http://vm0024:8080/captain/iso_album/ah13-promo_mc_sept-web-va.jpg\" alt=\"\"/>\r\n\t\t                            </td>\r\n\t\t                            <td style=\"vertical-align:top;text-align:right;height:65px;\"><img src=\"http://vm0024:8080/captain/iso_album/test2.png\" alt=\"\" width=\"auto\" height=\"65\"/></td>\r\n\t\t                        </tr>\r\n\t\t                        <tr>                          \r\n\t\t                            <td style=\"vertical-align:middle;padding-left:10px;height:968px;\" id=\"tdSizable\">\r\n\t\t                                <p><b>test Start a workshop</b><br/>\r\n\t\t                                <span style=\"font-size:14px;font-weight: bold;\"><i style=\"font-size: 18px;font-family: serif;\">\"</i> Révélez votre style !<i style=\"font-size: 18px;font-family: serif;\">\"</i></span></p>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<br/>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<br/>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<br/>\r\n\t\t                                <p style=\"color:#E20055;font-weight: bold;\">\r\n\t\t                                 On the Saturday 12 December 2015<br/>\r\n\t\t                                From 15h00 à 18h00\r\n\t\t                                </p>\r\n\t\t                                <br/>\r\n\t\t                                <p>\r\n\t\t                                  <b> To: </b> test\r\n\t\t                                </p>\r\n\t\t                                <p>\r\n\t\t                                  <b> Tel number</b> 0123456789\r\n\t\t                                </p>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<br/>\r\n\t\t                                <p style=\"color:#E20055;font-weight: bold;\">\r\n\t\t                                 Your friends are welcome<br/>\r\n\t\t                                Please feel free to bring your friends\r\n\t\t                                </p>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<br/><br/><br/>\r\n\t\t                                <b>Pippa SMITH,</b><br/>\r\n\t\t                                Administrateurs  Captain tortue group\r\n\t\t                            </td>                            \r\n\t\t                        </tr>\r\n\t\t                        <tr>\r\n\t\t                            <td style=\"text-align:right;vertical-align:bottom;height: 50px; border-top: solid 1px #868789\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img width=\"248\" height=\"auto\" src=\"http://vm0024:8080/captain/iso_icons/cpTortue_mailFooterLogo.jpg\" alt=\"logo\"/>\r\n\t\t                            </td>\r\n\t\t                        </tr>\r\n\t\t                    </table>\r\n\t\t                ","text":null,"subject":"Invitation à un atelier mode Révélez votre style !","from_email":"p.smith731@captaintortue.com; Pippa SMITH","from_name":null,"to":[{"email":"karenclakre@btinternet.com","name":"karenclakre@btinternet.com","type":"bcc"},{"email":"katkydaly@googlemail.com","name":"katkydaly@googlemail.com","type":"bcc"}],"important":false,"track_opens":null,"track_clicks":null,"auto_text":null,"auto_html":null,"inline_css":null,"url_strip_qs":null,"preserve_recipients":null,"view_content_link":null,"bcc_address":null,"tracking_domain":null,"signing_domain":null,"return_path_domain":null,"merge":false,"global_merge_vars":null,"merge_vars":null,"tags":null,"subaccount":null,"google_analytics_domains":null,"google_analytics_campaign":null,"metadata":null,"recipient_metadata":null,"attachments":null,"images":null},"async":false,"ip_pool":null,"send_at":null}"

任何人都可以帮忙吗?

您需要添加以下标头。 它对我有用的同样的错误

client.Encoding = Encoding.UTF8;

尝试查找非转义的 html 字符,如 © .我遇到了同样的错误,事实证明我需要使用 &#169;(没有 & 和 # 之间的空格)

相关内容

  • 没有找到相关文章

最新更新