简体   繁体   English

无法连接到远程服务器,

[英]Unable to connect to the remote server,

Simply, I want to send an email in my mvc aspnet application. 简单来说,我想在我的mvc aspnet应用程序中发送电子邮件。 my action method below : 我的动作方法如下:

 SmtpClient mailClient = new SmtpClient("127.0.0.1");
 NetworkCredential cred = new NetworkCredential("my mail address", "my password");
 mailClient.Credentials = cred;
 MailMessage contact = new MailMessage();
 contact.From = new MailAddress("my mail address");
 contact.Subject = "Subject";
 contact.IsBodyHtml = true;
 contact.Body = "Body";
 mailClient.EnableSsl = true;
 contact.To.Add("someone's mail address");
 mailClient.Send(contact);

But when I try this I got an error like that : 但是当我尝试这样做时,出现了这样的错误:

System.Net.Mail.SmtpException : {"Failure sending mail."} System.Net.Mail.SmtpException:{“发送邮件失败。”}

Inner Exception : {"Unable to connect to the remote server"} 内部异常:{“无法连接到远程服务器”}

I searched similar solutions but they say that You needed to set the credentials but I'm sure that I set the credentials correctly. 我搜索了类似的解决方案,但他们说您需要设置凭据,但是我确定我正确设置了凭据。 Also Windows Firewall is turned off. Windows防火墙也被关闭。 Thanks in advance. 提前致谢。

Sorry to say it, but your Exceptions are already very obvious! 不好意思说,但是您的异常已经很明显了!

It seems like u try it on a non SMTP server. 看来您在非SMTP服务器上尝试过。 Set one up and it should work then. 设置一个,它应该可以正常工作。

=> System.Net.Mail.SmtpException : {"Failure sending mail."} => System.Net.Mail.SmtpException : {"Failure sending mail."}

Else just check your connection/ premission to the server. 否则,只需检查您与服务器的连接/权限即可。

=> Inner Exception : {"Unable to connect to the remote server"} => Inner Exception : {"Unable to connect to the remote server"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM