我正在使用smtp谷歌的服务器通过我的联系表单发送电子邮件..在本地服务器它工作正常,但在Web服务器它显示此错误。首先,我使用端口号 587 这会导致错误“安全异常”并且错误在using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
行,但我已将端口更改为 25 ,并且它在行上显示此新错误。
smtp.Send(mail);
说明:
执行当前期间发生了未处理的异常 网络请求。请查看堆栈跟踪以获取更多信息 错误以及它在代码中的起源。
例外详情:
System.Net.Sockets.SocketException:尝试访问a 套接字以其访问权限禁止的方式74.125.206.108:25
我的代码是:
protected void send_Click(object sender, EventArgs e)
{
string smtpAddress = "smtp.gmail.com";
int portNumber = 25;
bool enableSSL = true;
string emailfrom = "isl@gmail.com";
string password = "******";
string subject = "Contact Form Data";
string emailto = "isl@gmail.com";
string name = n.Value;
string useremail = em.Value;
string phone = tel.Value;
string dept = dep.Value;
string dest = des.Value;
string adu = ad.Value;
string msg = mes.Value;
string body = "Name: " + name + " ;" + " Email: " + useremail + " ;" + "Telephone: " + phone + " ;" + " Departure Place: " + dept + " ;" + "Destination Place: " + dest + " ;" + " Adults: " + adu + " ;" + " ;" + "Children: " + chil + " ;" + "Message: " + msg + " ;";
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(emailfrom);
mail.To.Add(emailto);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
{
smtp.Credentials = new NetworkCredential(emailfrom, password);
smtp.EnableSsl = enableSSL;
smtp.Send(mail);
}
}
}
堆栈跟踪
[SocketException(0x271d):尝试访问a中的套接字 被访问权限禁止的方式74.125.206.108:25] System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)+208 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, 插座s4,插座s6,插座& socket,IPAddress&地址, ConnectSocketState状态,IAsyncResult asyncResult,Exception& 例外)+464
[WebException:无法连接到远程服务器] System.Net.ServicePoint.GetConnection(PooledStream PooledStream, 对象所有者,布尔异步,IPAddress&地址,插座& abortSocket, 插座及放大器; abortSocket6)+6662436 System.Net.PooledStream.Activate(Object owningObject,Boolean async,GeneralAsyncDelegate asyncCallback)+307 System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)+19 System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback,Int32 creationTimeout)+324 System.Net.Mail.SmtpConnection.GetConnection(的ServicePoint servicePoint)+141 System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) +170 System.Net.Mail.SmtpClient.GetConnection()+44 System.Net.Mail.SmtpClient.Send(MailMessage message)+1554
[SmtpException:发送邮件失败。] System.Net.Mail.SmtpClient.Send(MailMessage message)+1906 Contact.send_Click(Object sender,EventArgs e)in \ SMB-WHST-www02 \ whst_www02 $ \ ff8b1b \用户\ medviewair.uk \网络\ Contact.aspx.cs:51 System.Web.UI.WebControls.Button.OnClick(EventArgs e)+9628462 System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串 eventArgument)+103 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 eventArgument)+10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument)+13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) 1724
答案 0 :(得分:7)
Windows Update之后,Windows将保留某些端口,并且应用程序无法绑定到这些端口。请检查此命令
netsh接口ipv4显示排除的端口范围协议= tcp
答案 1 :(得分:2)
请检查您的Web服务器是否已正确配置并且已启动并正在运行。
如果您的应用程序抛出异常,请按照以下步骤进行操作
答案 2 :(得分:0)
我不得不禁用Kaspersky End Point Security防病毒软件
答案 3 :(得分:0)
我已禁用McAfee,但它确实有效,当然还有防火墙或防病毒设置
答案 4 :(得分:0)
该端口是否已在排他性中使用?使用NirSoft的“ CPorts”实用程序检查是否存在。