Smtp.Client.Send(Msg)重定向到错误页面 [英] Smtp.Client.Send(Msg) Redirects to Error page
本文介绍了Smtp.Client.Send(Msg)重定向到错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
实际上,我正在为忘记密码设计代码,这是提交电子邮件地址后button_click事件的代码。
我用aspspider.info和somee.com来托管我的网站。
aspspider.info : - 正确执行
somee.com: - SmtpClient.Send(Msg)重定向到错误页面
Actually, I'm designing code for forgot password and that is the code of button_click event after submitting email address.
I have used aspspider.info and somee.com to host my site.
aspspider.info :- Executing Properly
somee.com :- SmtpClient.Send(Msg) redirects to error page
if (ds.Tables[0].Rows.Count > 0)
{
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress("vikasparmar88@gmail.com");
// Recipient e-mail address.
Msg.To.Add(Temail.Text);
Msg.Subject = "Check Password";
Msg.Body = "Hi, <br />Please check your Login Detailss<br /><br />Your Username: " + ds.Tables[0].Rows[0]["Name"] + "<br /><br />Your Password: " + ds.Tables[0].Rows[0]["Password"] + "<br /><br />";
Msg.IsBodyHtml = true;
// your remote SMTP server IP.
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("My-email", "password");
smtp.EnableSsl = true;
smtp.Send(Msg);
error.ForeColor = Color.Green;
//Msg = null;
error.Text = "Your Password Details Sent to your mail";
// Clear the textbox valuess
Temail.Text = "";
}
else
{
error.ForeColor = Color.Red;
error.Text = "The Email you entered not exists.";
}
知道为什么会这样吗?
谢谢
Vikas
Any idea why this would be happening ?
Thanks
Vikas
推荐答案
这可能是防火墙阻碍或者也可能是其他问题,具体取决于您的SMTP位置服务器是(您是在本地使用IIS SMTP服务器吗?它是否正确安装/配置?)。
您应该将此代码包装在try / catch块中并记录任何异常。这样,您至少可以确定问题的可能原因(包括在已发布的代码中)。
It could be a firewall getting in the way or could also be some other issue depending upon where your SMTP server is (are you using the IIS SMTP server locally? Is it installed/configured correctly?).
You should really wrap this code up in a try/catch block and log any exceptions. That way, you'll at least be able to determine what the likely cause of the problem is (including in the published code).
这篇关于Smtp.Client.Send(Msg)重定向到错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文