开发者

Problem sending mail with simple .net application. Server refusal error

I have a very simple .net application for testing SMTP on .net. But i am receiving this weird error. "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"

SMTP server is remote and doesn't need any kind of authentication so i don't need credentials. But i can send mails from this computer with outlook using same smtp server and sam开发者_StackOverflow社区e smtp settings without any problem.

Any ideas? It will be appreciated so much.

Imports System.Net.Mail 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim smtp As New SmtpClient
    smtp.Host = "10.241.128.220"
    smtp.Port = 25
    smtp.Send("nuri-fatih.guler@rzb.ro", "nuri-fatih.guler@rzb.ro", "test", "test")
End Sub


Ensure that the machine you are sending the emails from has permissions to use this mail server as a relay. This is less a programming issue, and more a server issue, so it might be better answered at Serverfault.

Here's a good place to start, though: http://support.microsoft.com/kb/895853

Edit - added.

I found the list below at a different site.

These are the 4 most likely causes for the issue.

  1. there isn't any service running at the IP:Port you specified.
  2. there is a firewall in the way (at the client or server)
  3. there is a virus scanner in the way (at the client or server)
  4. Your mail server doesn't like the originating IP, so it is dropping the connection.

My answer above was to address point #4, since most mail servers allow you to block pass-through functionality and open it up to specific IP addresses.

So the SMTP server has to be configured to allow the IP address of the machine you're using to use it as a pass-through SMTP server, which is what you're doing when using the System.Net.Mail namespace and specifying a mail server other than local host.

Typically, when I have experienced issue #4, I could send using Outlook. In this situation, the following has to be true:

  1. The mail server must be using Exchange
  2. Outlook is connecting using MAPI (the default when connecting to an Exchange server).

In this case, Exchange works, because IMAP is not being blocked, BUT System.Net.Mail uses SMTP, and SMTP may be blocked when MAPI is not.


I discovered the problem. It was because of McAfee Antivirus. It blocked 25 port. I disabled it and problem has been solved. Thanks to everybody. Especially David.


  1. Outlook might not be using SMTP to send emails
  2. Are you sure Outlook is not connecting using SSL?
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜