4

I am developing an application for a server and it must send mail occasionally for notifications to users.

MailMessage mm = new MailMessage();

mm.To.Add("me@domain.net");
mm.From = new MailAddress("you@domain.net");
mm.Subject = "J/K";
mm.Priority = MailPriority.Normal;
mm.IsBodyHtml = false;
mm.Body = "Greetings and salutations";

SmtpClient client = new SmtpClient("host.address.lcl");
client.Send(mm);

If I put the app on an actual server it works fine, but on my workstation, depending upon how I access the code, it either silently fails or throws an exception. In either case a McLogEvent is generated:

Blocked by port blocking rule (Anti-virus Standard Protection:Prevent 
mass mailing worms from sending mail).

...and the exception says:

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 [IP & Port Numbers] 

It looks like a rule on my workstation is working to keep the mail from being generated, directly or indirectly, but I'm not sure what to make of the "actively refused it" part, since if the McLogEvent text seems to suggest that it wouldn't get that far.

I should point out that if I use System.Web.Mail it works great. The drawback being of course compiler messages about this namespace being deprecated in favor of System.Net.Mail.

Anyone have any idea of how to make McAfee cool with sending mail from my workstation?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Cyberherbalist
  • 12,061
  • 17
  • 83
  • 121
  • 2
    Not really an answer, but "actively refused" in normal circumstances means the TCP packet reached the remote machine, but it responded with a TCP RST ("reset/abort connection") packet because the requested port isn't available. In this case, McAfee has injected itself into the pipeline and is sending RST packets to your process when it sees outgoing packets destined for port 25 (SMTP) to effectively abort/block the connection. – Mike Spross Mar 19 '11 at 00:23
  • 1
    As for why it works with `System.Web.Mail` but not `System.Net.Mail`, `System.Web.Mail` is just a wrapper around Microsoft's older CDONTS and slightly newer CDOSYS libraries, whereas `System.Net.Mail` is a native SMTP client implementation. My guess is that McAfee is differentiating between mail coming from CDONTS/CDOSYS (and allowing it through) vs. mail that is coming directly from your .NET application, and assuming your .NET application is a rogue application. – Mike Spross Mar 19 '11 at 00:31

2 Answers2

7

Open mcafee console from the sys tray by right clicking on the McAfee icon and select VirusScan Console

View the properties under Task, Access Protection

Uncheck the rule that blocks outgoing messages on port 25.

edit - the exception saying that it was actively refused is just because McAfee isn't allowing you to make the connection on port 25 to anything, so the exception just thinks you tried a host which didn't have anything on 25 or had a firewall blocking 25.

It's worth pointing out that if your on a corporate network and you're running the enterprise version of McAfee, the setting may be configured at a higher level than your system, so you may not be able to change it - speak to your sysadmin if this is the case.

dotalchemy
  • 2,459
  • 19
  • 24
  • Although the exact steps given above do not correspond to the exact version of McAfee installed on my workstation, they are close enough that I found the setting that seems to govern in this case. It doesn't govern port 25, but allows specific inclusions and exclusion to the list of programs allowed to "mass mail." I cannot change the entry (or, rather it looks like I can, but it never actually changes), so I have to contact my network people. – Cyberherbalist Mar 21 '11 at 21:18
  • Is it possible to script this in command line and run? Or any registry setting can be made for the same to script this in command line? – Murali Murugesan Jul 07 '16 at 09:25
  • Hijack: on my laptop: with McAFee, can't send requests from VS. Without McAfee, can't send email on any port. Any recommendations? – Stephane Feb 05 '19 at 21:40
1

It depends if you're in an environment running EPO (McAfee ePolicy Orchestrator) or if your anti-virus is standalone. If EPO then you'll need to have your workstation (and program executable) unblocked in the EPO console.

nimizen
  • 3,345
  • 2
  • 23
  • 34