使用SmtpClient,并获得"目标机器积极地拒绝它与QUOT;它与、机器、目标、积极地

2023-09-07 09:06:48 作者:笑只不过是一种表情

我想使用System.Net.Mail用于应用程序发送电子邮件,但得到这个异​​常:

I am trying to use System.Net.Mail for an application to send an email, but get this exception:

System.Net.Mail.SmtpException:失败发送邮件。 --->   System.Net.WebException:无法连接到远程服务器--->   System.Net.Sockets.SocketException:无连接可以作出   因为目标机器积极地拒绝它198.238.39.170:25

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

在code我现在用的就是:

The code I am using is:

string mailserver = "Scanmail.ofm.wa.lcl";
MailMessage msg = new MailMessage("albert@einstein.net", "snark@snarky.com", "Very subjective", "A message body!");
SmtpClient client = new SmtpClient(mailserver);
client.Send(msg);

显然,上面的电子邮件地址是虚构的,但在实际code,它使用真实的电子邮件地址,在系统中。邮件服务器地址是准确的。

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.

我忍不住想,我需要把某种安全证书在那里,但不知道在哪里 - 尽管@ Andre_Calil的意见认为这不是问题,那可能是邮件服务器被配置为prevent我的机器无法连接。所以,这是怎么克服?

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?

推荐答案

因此​​,当我们在谈论,你的服务器可能配置为拒绝中继从每台机器,这是一个推荐的安全设置。

So, as we were talking, your server is probably configured to deny relay from every machine, which is a recommended security setting.

从开发机器,打开一个提示(命令),然后键入的telnet SMTP_SERVER_IP_ADDRESS 25 。该命令将尝试stablish端口25上的一个基本的socket连接,这是默认的SMTP端口。如果它是成功的,你还是要发现服务器是否需要身份验证。

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.

但是,如果它是不成功的,你必须把你的code搁置,直到你可以得到一个系统管理员的帮助。

However, if it's unsuccesful, you'll have to put your code on hold until you can get the help of a sysadmin.

另一件事尝试是从的应用程序服务器重复同样的测试的,因为SMTP服务器可以配置成允许APP_SERVER 拒绝everybody_else

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_server and deny everybody_else.

问候