-1

私はc#コードを介して送信グリッドによって送信されるメールを読む必要があります。

私はそのようなストリームを読みました

     --xYzZY
Content-Disposition: form-data; name="headers"

Received: by 127.0.0.1 with SMTP id 8KwcWqETbu Fri, 25 Jan 2013 03:49:42 -0600 (CST)
Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by mx5.sendgrid.net (Postfix) with ESMTPS id A1D5A2621B68 for <pk@replydev.socialboards.com>; Fri, 25 Jan 2013 03:49:42 -0600 (CST)
Received: by mail-ve0-f173.google.com with SMTP id b10so69883vea.32 for <pk@replydev.socialboards.com>; Fri, 25 Jan 2013 01:49:42 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=w5qN+xkC2AsH6lrtfF/wYnPJ3C3PTO0oVvChHKiLsXM=; b=hgrflJqveG6cOlK5XNz7qI3fJjIOvOeJsmZhyPU+vRFsKlLPctb91oGxz/0v+kzABj us04rC6cW6CWIIR4W1dYfUEpXYdBgbVoOMPs4ef005jMHPOfpMx81YAW6tpq1HQyLh1W 4n49LBm1GssCJhbhwSMUKRwIVqBmLtxMzVPnWVrCqMB8e2KSn78yw58JFOtf7qv+tKE3 oqa4n04ywmcVCKhEx2bhIvpo7IJQ5BjC62Q3iNdQgTJLw1eKQ9nMF8BTxXLFlFZK5HHb fpLFkgiIGqqYJioKtyS0slkJQA1P8OSrjkDnlmLXJU7btatnxd+a94wYKNB6yHwYpL+M f4SQ==
MIME-Version: 1.0
X-Received: by 10.52.179.136 with SMTP id dg8mr4231328vdc.81.1359107382079; Fri, 25 Jan 2013 01:49:42 -0800 (PST)
Received: by 10.58.155.42 with HTTP; Fri, 25 Jan 2013 01:49:42 -0800 (PST)
Date: Fri, 25 Jan 2013 15:19:42 +0530
Message-ID: <CAJfhHSq2qTRHK_0_6jWQyTd9ecB61SJYDyy8mM7G3-atUN13qA@mail.gmail.com>
Subject: dfdsfdsfds
From: Pragati Kumar <pragati.kumar@sdplabs.com>
To: Eric Test <pk@replydev.socialboards.com>
Content-Type: multipart/alternative; boundary=bcaec5014c15b870c904d419d845
X-Gm-Message-State: ALoCoQmTr/zLwW3mbRCZRyL5EOYaPnPrpXB+GEtN+sTQ1PdGB/ulN//n2SaQiYaSbKRyVaqLJfBq

--xYzZY
Content-Disposition: form-data; name="dkim"

none
--xYzZY
Content-Disposition: form-data; name="to"

Eric Test <pk@replydev.socialboards.com>
--xYzZY
Content-Disposition: form-data; name="html"

<div dir="ltr"><br clear="all"><div style>fdsfdsfdsfdsfdsfds</div>-- <br><div dir="ltr"><div>Thanks With Regards.</div><div><br></div><div><b>Pragati Kumar Singh</b></div><div><b>Software Developer (.NET)</b></div><div><b>Mob:  +91 902-363-6285</b></div>
<div><b><br></b></div><div><b>SDPLabs</b></div><div><b><a href="mailto:pragati.kumar@sdplabs.com" target="_blank">pragati.kumar@sdplabs.com</a></b></div><div><b><a href="http://www.sdplabs.com" target="_blank">www.sdplabs.com</a></b></div>
<div><br></div><div>India:  +91 0172 401 0125 (Office)</div><div>           +91 0172 465 0337 (Office)</div><div>USA:   +1 646-462-4634 (Office)</div><div>           +1 646-789-5302 (Cell)</div><div>Fax:   +1 928-563-1783</div>
</div>
</div>

--xYzZY
Content-Disposition: form-data; name="from"

Pragati Kumar <pragati.kumar@sdplabs.com>
--xYzZY
Content-Disposition: form-data; name="text"

fdsfdsfdsfdsfdsfds
-- 
Thanks With Regards.

*Pragati Kumar Singh*
*Software Developer (.NET)*
*Mob:  +91 902-363-6285*
*
*
*SDPLabs*
*pragati.kumar@sdplabs.com*
*www.sdplabs.com*

India:  +91 0172 401 0125 (Office)
           +91 0172 465 0337 (Office)
USA:   +1 646-462-4634 (Office)
           +1 646-789-5302 (Cell)
Fax:   +1 928-563-1783

--xYzZY
Content-Disposition: form-data; name="spam_report"

Spam detection software, running on the system "mx5.sendgrid.net", has
identified this incoming email as possible spam.  The original message
has been attached to this so you can view it (if it isn't spam) or label
similar future email.  If you have any questions, see
the administrator of that system for details.

Content preview:  fdsfdsfdsfdsfdsfds -- Thanks With Regards. *Pragati Kumar
  Singh* *Software Developer (.NET)* *Mob:  +91 902-363-6285* * * *SDPLabs* *pragati.kumar@sdplabs.com*
   *www.sdplabs.com* India:  +91 0172 401 0125 (Office)  +91 0172 465 0337 (Office)
   USA:  +1 646-462-4634 (Office)  +1 646-789-5302 (Cell) Fax: +1 928-563-1783
   [...] 

Content analysis details:   (-0.7 points, 5.0 required)

 pts rule name              description
---- ---------------------- --------------------------------------------------
 0.0 HTML_MESSAGE           BODY: HTML included in message
-0.7 RCVD_IN_DNSWL_LOW      RBL: Sender listed at http://www.dnswl.org/, low
                            trust
                            [209.85.128.173 listed in list.dnswl.org]
 0.0 T_MIME_NO_TEXT         No text body parts


--xYzZY
Content-Disposition: form-data; name="envelope"

but I am unable verify its format so that it could be inserted into our database.
Please help to decode it so that I can read the following fields in the best possible way.
1. To
2. From
3. BCC
4. Body
5. Subject
6. Attachment.

Thanks in anticipation


{"to":["pk@replydev.socialboards.com"],"from":"pragati.kumar@sdplabs.com"}
--xYzZY
Content-Disposition: form-data; name="attachments"

0
--xYzZY
Content-Disposition: form-data; name="subject"

dfdsfdsfds
--xYzZY
Content-Disposition: form-data; name="spam_score"

-0.689
--xYzZY
Content-Disposition: form-data; name="charsets"

{"to":"UTF-8","html":"ISO-8859-1","subject":"UTF-8","from":"UTF-8","text":"ISO-8859-1"}
--xYzZY
Content-Disposition: form-data; name="SPF"

none
--xYzZY--

これをjson形式にシリアル化する必要があります。

私が試してみました

 private string RequestInputStreamToString()
    {
        System.Text.StringBuilder sb = new StringBuilder();
        int streamLength;
        int streamRead;
        System.IO.Stream s = HttpContext.Current.Request.InputStream;
        streamLength = Convert.ToInt32(s.Length);
        Byte[] streamArray = new Byte[streamLength];
        streamRead = s.Read(streamArray, 0, streamLength);
        for (int i = 0; i < streamLength; i++)
        {
            sb.Append(Convert.ToChar(streamArray[i]));
        }
       return sb.ToString();
    }
 string jsontext =RequestInputStreamToString();
 var json = JObject.Parse(jsontext);

しかし、それは大騒ぎのエラーです

Error reading JObject from JsonReader.

詳細については、 http://sendgrid.com/docs/API_Reference/Webhooks/parse.htmlを確認してください 。ただし、phpで提供されており、C#で必要です。

4

1 に答える 1

0

苦労した後、私は解決策を見つけました。これらはmultipart/form-dataのコンテンツです。すべてのデータを読み取ることができます

    HttpContext context;
    String to=context.Request.Params["to"];
    String from=context.Request.Params["from"];
    String html=context.Request.Params["html"];
        .......etc..............

コンテンツとノードを読み取った後、クラスプロパティに渡すことができ、さらに要件に応じてjsonまたはxmlにシリアル化できます。

于 2013-02-11T12:05:17.243 に答える