C# 使用 SmtpClient,并得到“目标机器主动拒绝它”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11621373/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using SmtpClient, and getting "the target machine actively refused it"
提问by Cyberherbalist
I am trying to use System.Net.Mail for an application to send an email, but get this exception:
我正在尝试将 System.Net.Mail 用于发送电子邮件的应用程序,但出现此异常:
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 198.238.39.170:25
System.Net.Mail.SmtpException:发送邮件失败。---> System.Net.WebException: 无法连接到远程服务器 ---> System.Net.Sockets.SocketException: 无法建立连接,因为目标机器主动拒绝它 198.238.39.170:25
The code I am using is:
我正在使用的代码是:
string mailserver = "Scanmail.ofm.wa.lcl";
MailMessage msg = new MailMessage("[email protected]", "[email protected]", "Very subjective", "A message body!");
SmtpClient client = new SmtpClient(mailserver);
client.Send(msg);
Obviously the email addresses above are fictional, but in the actual code it uses real email addresses in the system. The mail server address is accurate.
显然,上面的电子邮件地址是虚构的,但在实际代码中,它使用了系统中的真实电子邮件地址。邮件服务器地址是准确的。
I am tempted to think that I need to put some kind of security credentials in there, but not sure where - although @Andre_Calil's advice suggests this is not the problem, and that possibly the mail server is configured to prevent my development machine from connecting. So how is this to be overcome?
我很想认为我需要在那里放置某种安全凭证,但不确定在哪里 - 尽管@Andre_Calil 的建议表明这不是问题,而且邮件服务器可能配置为阻止我的开发机器连接。那么如何克服呢?
采纳答案by Andre Calil
So, as we were talking, your server is probably configured to deny relay from every machine, which is a recommended security setting.
因此,正如我们所说,您的服务器可能配置为拒绝来自每台机器的中继,这是推荐的安全设置。
From your development machine, open a prompt (command) and type telnet SMTP_SERVER_IP_ADDRESS 25. This command will try to stablish a basic socket connection on port 25, which is the default SMTP port. If it's successful, you'll still have to discover whether the server requires authentication.
在您的开发机器上,打开一个提示 ( command) 并输入telnet SMTP_SERVER_IP_ADDRESS 25. 此命令将尝试在端口 25(默认 SMTP 端口)上建立基本套接字连接。如果成功,您仍然需要发现服务器是否需要身份验证。
However, if it's unsuccesful, you'll have to put your code on hold until you can get the help of a sysadmin.
但是,如果不成功,则必须暂停代码,直到获得系统管理员的帮助。
One other thing to try is to repeat this same test from a app server, because the SMTP server may be configured to allow app_serverand deny everybody_else.
要尝试的另一件事是从应用程序服务器重复相同的测试,因为 SMTP 服务器可能配置为allow app_server和deny everybody_else。
Regards
问候

![C# 哪个最适合用于从 byte[] 创建文件?](/res/img/loading.gif)