Asp.net smtp连接在telnet中工作,但在ASP中不工作--相同的服务器,相同的凭据
我正在尝试使用我的SendGrid帐户从ASP.NET发送电子邮件。它可以在我的开发机器上工作,但不能在生产环境中工作,即使凭据是相同的。同样,在生产环境中,我可以通过telnet(使用base64编码凭据)连接到SMTP服务器,但ASP站点无法连接--我收到错误“不允许未经身份验证的发件人” 我尝试了混合端口号(25587465——我的站点是SSL)。使用端口465超时。25和587返回并立即响应——但有登录错误。这真的令人困惑,因为正如我所说的,在开发机器和生产环境中都是相同的凭证 我简单地看了一下MicrosoftNetworkMonitor3.4,但对它一无所知。我希望它能告诉我正在发送的blow-by-blow命令,因为我怀疑该网站正在做一些与telnet连接方式略有不同的事情,但我不知道是什么 注意:我还询问了我的web主机,这些端口上的传出流量是否在生产防火墙上被阻止,但它们没有 下面是实际的代码——就像我说的,在本地主机上工作正常,但SMTP连接在生产环境中失败Asp.net smtp连接在telnet中工作,但在ASP中不工作--相同的服务器,相同的凭据,asp.net,telnet,sendgrid,Asp.net,Telnet,Sendgrid,我正在尝试使用我的SendGrid帐户从ASP.NET发送电子邮件。它可以在我的开发机器上工作,但不能在生产环境中工作,即使凭据是相同的。同样,在生产环境中,我可以通过telnet(使用base64编码凭据)连接到SMTP服务器,但ASP站点无法连接--我收到错误“不允许未经身份验证的发件人” 我尝试了混合端口号(25587465——我的站点是SSL)。使用端口465超时。25和587返回并立即响应——但有登录错误。这真的令人困惑,因为正如我所说的,在开发机器和生产环境中都是相同的凭证 我简单地
[AllowAnonymous]
[HttpPost]
public ActionResult ResetPasswordSend(string email)
{
List<string> userList = new List<string>();
try
{
string[] invalidChars = new string[] { ";", "," };
foreach (var invalidChar in invalidChars) if (email.Contains(invalidChar)) throw new Exception("Email contains invalid character.");
int count = 0;
// since emails are not unique, I must launch resets for all of them
var users = _db.HsProfile.Query("[Email]=@0", SqlDb.Params(email));
foreach (var profile in users)
{
count++;
userList.Add(profile.UserName);
var token = WebSecurity.GeneratePasswordResetToken(profile.UserName, 15);
WebMail.Send(profile.Email, "HumaneSolution.com Password Reset for user " + profile.UserName,
"You received this email because you or someone with your email address requested a password reset on HumaneSolution.com. " +
"If you didn't do this, then you don't need to take any action, and nothing will happen.\n\n" +
"To proceed with the password reset, click the link below within 15 minutes:\n\n" +
Url.BaseUrl("Account/EnterNewPassword/" + token) + "\n\n" +
"Sent to: " + email + " at " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + "\n" +
"User name: " + profile.UserName);
}
if (count == 0) throw new Exception("Email " + email + " is not registered at HumaneSolution.com.");
}
catch (Exception exc)
{
ViewBag.Error = exc.Message;
}
return View(userList);
}
[AllowAnonymous]
[HttpPost]
public ActionResult ResetPasswordSend(字符串电子邮件)
{
List userList=新列表();
尝试
{
字符串[]invalidChars=新字符串[]{;“,”,“};
foreach(invalidChars中的var invalidChar)if(email.Contains(invalidChar))抛出新异常(“email包含无效字符”);
整数计数=0;
//因为电子邮件不是唯一的,所以我必须为所有邮件启动重置
var users=_db.HsProfile.Query(“[Email]=@0”,SqlDb.Params(Email));
foreach(用户中的var配置文件)
{
计数++;
userList.Add(profile.UserName);
var token=WebSecurity.GeneratePasswordResetToken(profile.UserName,15);
WebMail.Send(profile.Email,“HumaneSolution.com用户密码重置”+profile.UserName,
“您收到此电子邮件是因为您或您的电子邮件地址的人请求在HumaneSolution.com上重置密码。”+
如果不这样做,则不需要采取任何行动,也不会发生任何事情。\n\n+
要继续密码重置,请在15分钟内单击下面的链接:\n\n+
Url.BaseUrl(“帐户/输入新密码/“+令牌)+”\n\n“+
已发送至“+DateTime.Now.ToLongDateString()+”+DateTime.Now.ToLongTimeString()+”处的“+email+”\n+
“用户名:”+profile.UserName);
}
如果(count==0)抛出新异常(“Email”+Email+“未在HumaneSolution.com上注册”);
}
捕获(异常exc)
{
ViewBag.Error=exc.消息;
}
返回视图(用户列表);
}
根据SendGrid的建议,我重新编写了电子邮件代码,因此它不使用WebMail.Send,而是显式使用SmtpClient和MailMessage对象。SendGrid说ASP.NET如何从配置文件自动加载凭据可能存在某种时间问题。下面就是他们所说的:
您是否碰巧将SendGrid凭据存储在配置文件中,与连接到SMTP服务器的代码分开?我问这个问题的原因是因为我看到像这样的rails和C#配置由于没有在正确的时间传递凭据而收到未经验证的错误。通常通过将凭证直接与代码一起移动而不是单独的配置文件来解决此问题。试一试,看看你是否注意到了差异。对不起,我不确定你在说什么——你看到我需要发布代码示例了吗?是的,iamkrillin要求你发布代码示例。我能问一下谁是你的主持人吗?GoDaddy?主机由Connectria提供