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.
- there isn't any service running at the IP:Port you specified.
- there is a firewall in the way (at the client or server)
- there is a virus scanner in the way (at the client or server)
- 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:
- The mail server must be using Exchange
- 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.
- Outlook might not be using SMTP to send emails
- Are you sure Outlook is not connecting using SSL?
精彩评论