使用SendGrid SMTP电子邮件提交错误请求错误 [英] Bad Request error using SendGrid SMTP email submission

查看:1588
本文介绍了使用SendGrid SMTP电子邮件提交错误请求错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用C#中MVC4 ASP.NET 4.5。

I am currently using C# in MVC4 ASP.NET 4.5.

我的应用程序创建一个用户,然后提交注册电子邮件到使用来验证他们的电子邮件。为了创建这个剧本,我也跟着这个教程:的如何发送电子邮件使用SendGrid使用Windows Azure

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: How to Send Email Using SendGrid with Windows Azure

我使用的是最新版本的 SendGrid(2.1.1)

I am using the latest version of SendGrid (2.1.1)

code特定的命名空间中使用:

Code specific namespaces being used:

using SendGridMail;
using System.Net;
using System.Net.Mail;

下面是我的code,创造了SendGrid邮件:

Here is my code that creates the SendGrid mail message:

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

然后我去发送电子邮件:

Then I go to send the email:

//Create login info for email
NetworkCredential credentials = new NetworkCredential("username", "password");
var trasnportSMTP = Web.GetInstance(credentials);
trasnportSMTP.Deliver(message); //smtp.sendgrid.net Send message

在最后一行,其中trasnportSMTP.Deliver(消息);我得到这个错误:

On the last line where "trasnportSMTP.Deliver(message);" I get this error:

中的服务器错误'/'应用。

Server Error in '/' Application.

坏请求

说明:当前Web请求的执行过程中发生未处理的异常。有关详情,请堆栈跟踪
  有关错误的信息以及它起源于code。

Description: 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.

异常详细信息:的System.Exception:坏请求

Exception Details: System.Exception: Bad Request

我同时发现跟踪的唯一的事情就是在查看详细信息异常快照和输出窗口。

我注意到:
TargetSite = {无效CheckForErrors(System.Net.Http.Htt presponseMessage)},
返回类型为{名称=虚空全名=System.Void},
ReflectedType是{名称=网络全名=SendGridMail.Web},
CustomAttributes - 计数= 0,
NAME =CheckForErrors
这是在模块{} SendGridMail.dll。

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}.

另外,在我的输出,有以下内容:类型System.FormatException的第一次机会异常出现在System.dll中步骤分为:步进比非用户code'SendGridMail.Web.Deliver'

Also in my output, there is the following: "A first chance exception of type 'System.FormatException' occurred in System.dll Step into: Stepping over non-user code 'SendGridMail.Web.Deliver'"

谁能给我为什么这个错误发生更深入的了解。我使用的是正确的用户名和密码是在Azure上的SendGrid帐户。

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.

感谢您的时间提前。

推荐答案

尝试添加受您的留言

message.Subject = "this is the subject";

这应该这样做,我遇到了同样的问题,当我与此库玩。

That should do it, I ran into the same problem when I was playing with this library.

这篇关于使用SendGrid SMTP电子邮件提交错误请求错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆