我最近收到了错误消息: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.com" password="0545674811" />
</smtp>
</mailSettings>
请帮忙!
答案 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);