我使用SMTP谷歌的服务器,通过我接触form..In本地服务器发送电子邮件,它工作正常,但在Web服务器时,它显示了这个error.First,我使用的端口号587,其提供了错误“安全例外”的错误在线using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber)),但我已将端口更改为25,它在线上给出了这个新错误。
smtp.Send(mail);
Run Code Online (Sandbox Code Playgroud)
说明:
执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详情:
System.Net.Sockets.SocketException:尝试以访问权限禁止的方式访问套接字 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 = …Run Code Online (Sandbox Code Playgroud)