无法连接到远程服务器错误

时间:2013-06-08 09:03:30

标签: asp.net email smtp

我最近收到了错误消息:ystem.Net.Mail.SmtpException:发送邮件失败。 ---> System.Net.WebException:无法连接到远程服务器---> System.Net.Sockets.SocketException。 而且我之前也是这样,它在2周前就运行良好 我的C#服务器端代码:

MailMessage myEmail = new MailMessage()
                    {
                        Subject = "Message from website user:" + Name + "",
                        Body = "Email Address: " + email + Environment.NewLine + Environment.NewLine + "Message:" + Environment.NewLine + message,
                        IsBodyHtml = false,
                        From = new MailAddress(email, Name)
                    };

                    myEmail.To.Add(new MailAddress("yakov_mora@gmail.com‏"));
                    SmtpClient server = new SmtpClient();
                    server.Port = 25;
                    server.Send(myEmail);

我的webconfig:

system.net>
<mailSettings>
  <smtp deliveryMethod="Network">
    <network port="587" host="smtp.gmail.com"   enableSsl="true"   defaultCredentials="false" userName="yakov_mora@walla.c‏om" password="0545674811" />
  </smtp>
</mailSettings>

请帮忙!

1 个答案:

答案 0 :(得分:0)

不要在公共论坛中添加您的用户名/密码.. 反正把端口去掉

        myEmail.To.Add(new MailAddress("yakov_mora@gmail.com‏"));
        SmtpClient server = new SmtpClient();
        //server.Port = 25; not needed, remove this line
        server.Send(myEmail);