1

我想知道是否有人使用 SendGrid 的 Parse API 来使用 ASP.NET MVC 接收电子邮件。

我根据他们的说明设置了我的 SendGrid 帐户:http: //sendgrid.com/documentation/display/api/Parse

当我向我网站上的任何地址发送电子邮件时,我会调用我的 ASP.Net MVC ActionMethod,但是我看不到有关请求的任何信息。

我尝试访问 action 方法中的 Request 对象,它说 Length 大约为 12KB,但我没有看到我的信息。- Request.Form 没有任何内容 - Request.Files.Length 为 0 - Request.InputStream.Length 为 0

此外,如果我创建了一个 FormCollection 参数,它会变为空,并且如果我在 Action Method 中为公共字段(to、from、html、text)设置字符串参数,则在处理请求时它们都为空。

有人成功使用过这个吗?我错过了什么?

谢谢

4

1 回答 1

0

您需要关闭输入验证。它会在有数据的字段上抛出异常。否则,信息应该在 Request.Form 集合中可用

[HttpPost]
[ValidateInput(false)]
public ActionResult SendGrid(string from, string to, string text, string subject) //...
{                  
       ProcessEmail(from,to,text,subject...); // your function here
       return new EmptyResult();
}

在 MVC 中,您还必须在 web.config 中设置 requestValidationMode="2.0" ,否则它仍然会引发表单验证。

 <system.web>
  <httpRuntime requestValidationMode="2.0"/>
 </system.web>
于 2011-09-29T02:00:30.983 回答