2

我最近收到错误:ystem.Net.Mail.SmtpException:发送邮件失败。---> System.Net.WebException:无法连接到远程服务器 ---> System.Net.Sockets.SocketException。而且我以前从来没有这样做过,就在两周前,我的 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);

我的网络配置:

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>

请帮忙!

4

1 回答 1

0

不要在公共论坛中添加您的用户名/密码。无论如何,删除端口

        myEmail.To.Add(new MailAddress("yakov_mora@gmail.com‏&quot;));
        SmtpClient server = new SmtpClient();
        //server.Port = 25; not needed, remove this line
        server.Send(myEmail);
于 2021-06-16T06:08:39.670 回答