Using SmtpClient, and getting “the target machine actively refused it”

让人想犯罪 __ 提交于 2019-12-21 12:35:26

问题


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

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

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);

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?


回答1:


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.

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

Regards



来源:https://stackoverflow.com/questions/11621373/using-smtpclient-and-getting-the-target-machine-actively-refused-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!