Reputation: 158
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 same 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("[email protected]", "[email protected]", "test", "test")
End Sub
Upvotes: 2
Views: 4459
Reputation: 158
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.
Upvotes: 1
Reputation: 73564
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.
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:
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.
Upvotes: 4
Reputation: 6381
Upvotes: 0