【发布时间】:2016-12-28 12:25:10
【问题描述】:
我在我的网站上有联系表格。使用 GoDaddy 进行 Windows 托管。当我在本地主机中测试联系人时,它可以正常工作并发送邮件,但在托管时会出现异常。
System.Net.Mail.SmtpException:发送邮件失败。 ---> System.Net.WebException:无法连接到远程服务器 ---> System.Net.Sockets.SocketException:试图以访问权限 74.125.130.108:587 禁止的方式访问套接字在 System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) 在 System.Net.ServicePoint.ConnectSocketInternal (Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- 内部异常堆栈跟踪结束 --- 在 System.Net.PooledStream.Activate(Object owningObject 的 System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) , 布尔异步, GeneralAsyncDelegate asyncCallback) 在 System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) 在 System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate e asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net .Mail.SmtpClient.Send(MailMessage message) --- 内部异常堆栈跟踪结束 --- 在 System.Net.Mail.SmtpClient.Send(MailMessage message) 在 DynamicPage.sendInquiry_Click(Object sender, EventArgs e) 在 G: \PleskVhosts\brandstik.in\httpdocs\DynamicPage.aspx.vb:173 行
try {
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient();
mail.To.Add("abc@gmail.com");
mail.From = new MailAddress(inquiryEmail.Text);
mail.Subject = "Quote Request For " + quoteID.Text;
mail.Body = "New Quote request from customer<br /><br/>Customer Name - '" + inquiryName.Text + "' <br />Customer Email - '" + inquiryEmail.Text + "'<br />Customer Contact - '" + inquiryNumber.Text + "'<br />Comment - '" + inquiryMessage.Text + "'";
mail.IsBodyHtml = true;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("xyz@doamain.com", "1234567890");
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
Response.Write("Sent");
} catch (Exception ex) {
//Response.Write("<script language='javascript'>alert('Your SMTP Server needs to get configured to contact form work.');</script>")
Response.Write(ex);
}
【问题讨论】:
-
联系 GoDaddy 支持并确认该应用未被阻止!
-
您可能需要使用 HTTP 而不是 SMTP 访问您的 gmail 以绕过 GoDaddy 的限制。考虑 Gmail API:developers.google.com/gmail/api/guides
标签: c# asp.net vb.net sockets email