Prevent Anti-Virus to block outgoing email with C# - c#

I have an application with a static class that is capturing all errors that happens during the runtime (if its the case) and when process is done, it sends out an email with the list of errors so I or any other developers can address those errors.
However my problem is that McAfee is blocking the request, as if it was a kind of virus. I do not have rights on my machine to edit McAfee settings, is it possible to fix it through C# code?
Thank you

Probably McAfee is blocking outgoing connections on port 25 (SMTP), only allowing a white list of applications to send email.
What you can do is:
Put the email in a mailto:// url. Execute the mailto:// as if it is a normal command line. This will ask for input from the user, but you can create a nice template for the user. (syntax)
Send the email through your normal email client (Outlook, Notes), if they have an API for that.
Use a Http/Web based provider that has an API. Public ones are probably also blocked by McAfee. But you could create & host a service yourself. Be very carefull to only allow traffic from within your company.
Maybe you company has a "drop folder", where you can drop emails that are picked up by the email server.

Depending on what/why McAfee is flagging it, more than likely you will not be able to get around it.
You will want to see if you can find out if McAfee is flagging it due to the port being used, or if there is any other information as to why the individual message is not going.

No. And yes.
No, you can't force McAffee to not flag your email from code, if that's what you mean.
Yes, you can prevent McAffee or other virus scanners from flagging your emails as suspicious. Here are a couple of things I try to make sure of:
That your all addresses (especially from: and reply-to:) are valid.
That the the name you're sending from is actually the name of a the correct person in your active directory.
You could also ask your system administrators to put your "from:" address on a global whitelist so that it always goes to the client.
Are you attaching executables? Are you sure you aren't attaching any viruses? ;-)

From what I recall, I think McAfee has a list of programmes that are allowed to send emails, if your program is not added to this list, then your emails will not get sent.
This is a big support problem, as you will find your customers have a 101 different virus checkers all setup in different ways.
You may be able to setup a email server to use a none standard port, then send emails to that port.
For testing, attaching to the McAfee process with a debugger and then killing it can work well...

Related

Sending E-mail to localhost / "capturing" outgoing e-mail

I work with a dozen pieces of equipment whose operating software has the option to send e-mails on error. I would prefer to capture the details of that e-mail on the host PCs that run them (i.e. for logging, communicating details automatically via Slack, etc.) rather than them going to an inbox somewhere.
Is there a way to have the software e-mail an address that is essentially a lightweight piece of code running on the same PC mimicking something like an SMTP server (that will allow me to get after the message's contents)? Other solutions I have seen are along the lines of setting up a full-blown server which seems like overkill.
You may configure SmtpClient to save email to a specific folder instead of sending it over the wire. Check this answer.
Also you must design your system in the way it could work with different implementations of your 'sender', so that you can replace it when you need that, for example during testing. In this case you can easily provide proxy implementation that will capture email content and then send it to localhost, or add aspects (make retries, logs performance...).

How to notify a person when this goes down?

I made a simple notifier command line application in C#. Basically I use the windows task scheduler and set it up to run this command line application at a certain time.
When this time is hit the command line application is ran all notifications are grabbed from a database(using linq to sql) formatted and sent by smtp to the right people.
Now how should I handle these scenarios
A database error occurs
Solution: Send a email to the admin to notify them that it failed and to check it out.
A smtp error occurs
Solution: ?????
So these are really the two things that could go wrong. There could be different combination's of this.
Database error might occur and and smtp might occur too, Or only one or the other might occur.
So how to get this information to an admin or someone so they can fix it. I highly doubt that an admin would go and check every single day to see if the notification thing worked or not.
So basically how to make it fail safe or at least make it so that if something goes wrong a admin can come fix and it and just run the notifier manually and get everything back in sync.
You have a couple options.
Write the error information to a log. Make it a procedure for some operator to check the log every so often.
Have it call some other service?
However, if the database is used by more than just your app, it's entirely possible that someone else will notice. Same thing with the email server. If it's down, then I bet a lot of people will be making phone calls. Note that your situation precludes lost network connectivity (like a dead switch or misconfigured router).
Incidentally if it detects SMTP is back up, then it should notify someone that it was down for a given time period. Same thing about the database server.
Finally, ALL error conditions should be written to your system log. It's pretty trivial to write to the windows event logs. If your system administrators are following commonly accepted protocols they should be monitoring those pretty often anyway.
Logging an Error to the EventLog could also be an option, providing that the Admin either checks the EventLog regularly or that you have monitoring systems that aggregate those errors.
You could use an SMS gateway or attach a cellphone to the server and have it send a text message to an admin when something has gone horribly wrong.
But you can take this even further:
What if you lose network connectivity
(a switch or cable gone bad for
example)?
What if the power goes down
(when is the last time you tested the
UPS)?
Depending on your needs (and the business cost of not sending out these notifications in short notice), you may need a full-fledged monitoring solution.
So the main problem is that you do not know how to notify the admin in case of an SMTP server failure. You have several options, assuming the admin's e-mail account is not residing on the same server.
First option: You could set up a cgi mail script on another server and contact that via http to send the e-mail.
Second option: Use an smtp client and set it up to contact the receiver's smtp server for sending the e-mail directly (instead of going through the local smtp server).
BTW: Some e-mail providers offer text message notifications for e-mails originating from a certain address. That's very handy if the server goes down while the admin is away from his desk.
For your DB errors, you could hardcode in a (set of) email address for DB errors to be sent to.
As for the SMTP errors, you can either do a "send email when smtp recovers", or you have to have an alternate method for alerting your admins. This could be a backup SMTP server, a SMS gateway (as someone else mentioned), or even something such as someones desktop in the network popping up an alert if it doesn't receive some type of "everything is ok" alert/message from the box running the script.

Is it possible to find POP3 server for any email id using .net or PHP?

Is it possible to find POP3 server address for any given email id (like sam#mycustomdomain.com)? If yes, please provide some guidance preferably in PHP or .Net.
Edit :
I get addresses by querying MX record but those are not always the same which people use to fetch their emails.
I don't think you can "guess" the POP3 server for any email address and be right each time, no : the POP3 server can either :
be something like pop.thedomainnameintheaddress
or something totally different, like ssl.hostingcompany.com
In the first case, you could try to guess -- and sometimes be right... But in the second, you don't stand quite a chance.
You might want to take a look at Thunderbird 3 : I think it includes some auto-configuration mecanism about that : you enter your e-mail address, and it tries to find the POP server for your.
Not sure how it works, but I suppose there is a database containning that kind of informations, that Thunderbird sends requests to ; that would be the "best" solution, I'd say, as it can be updated without having to change Thunderbird itself, and doesn't rely on "guessing".
About Thundrbird's autoconfiguration mecanism, here's an interesting link : https://wiki.mozilla.org/Thunderbird:Autoconfiguration#Implementation -- especially the third point, which links to a directory where you can find configuration files for lots of domains.
For instance : https://live.mozillamessaging.com/autoconfig/gmail.com
Gets you an XML file indicating how Thunderbird has to be configured for #gmail.com emails.
And there's quite a couple of configuration files for other domains -- so this might be an interesting idea, at least for "well-known" domains ;-)
Of course, this doesn't solve the problem for non-well-known domains...
I don't think so; at least, not in a general way. Emails are just forwarded on to the right domain, and handled internally. For instance, my email address is stored on a server that provides both IMAP and POP access, and also forwarded to a webmail provider, who provide IMAP and POP access. So the question 'what's its POP3 server?' doesn't really make sense.
No, not really. It is however possible to find an smtp server for an email address. It is really not specific to any programming language, but the way you would go about it would be extract domain from email address (eg. me#somedomain.com => somedomain.com) and then make a dns query with type=MX. This will return the servers that accept mails for that domain, in order of priority.
If the question is, "For any given email address is there an automatic way to find the address of a POP3 server for it?" I'd say the answer is no.
Some people perhaps don't have POP3 access to their emails at all, and many people such as myself have our own domain hosted at a service provider and the POP3/IMAP servers are under the service provider's domains.

How do I test my email settings without sending a message?

As part of my app's config process, I have a sanity checker that validates all user-supplied data. This includes email server settings that the app uses to send email.
I'd like a simple sanity check on those settings without actually sending any email. It'd be great if this could support all standard flavors of SMTP setups including those with authentication/ssl/etc.
It doesn't need to be exhaustive but the more coverage, the better.
Currently all I do is verify I can open a connection to the given server on the given port. Something a little deeper would be nice.
Note: I'm not trying to validate email addresses--that's not relevant to this question.
You just open a raw connection to the server & port that the user supplies and do a
HELO Server.Domain.Com
Mail From: validaccount#domain.com
to see if you get a valid HELO response & Sender OK Response
(if smtp authentication is enabled).
Same as you would do if you telnet direct to the server.
http://www.petri.co.il/test_smtp_service.htm
This might also be useful
http://qmail.jms1.net/test-auth.shtml
I'm sure someone brighter and more qualified will pipe up with a better answer. However, at first blush I'd say that you cannot verify the ability to successfully send email without actually sending an email.
However, if you want to automate the process, you can have a 'MyApp_SanityCheck#gmail.com' (or your local domain) address.
Then you can create a watchdog application that monitors that email address, or just a simple app which programmatically interfaces with that email address and checks if an email was received within X minutes. This way you can be 100% certain that the emails are able to be sent out.
This link shows how to programmatically check gmail addresses.
An important note: If you application is sending out external emails, then it would be best if the email address you use is external, because it is possible that your server could be unable to send external emails, but internal emails go through just fine, and in that case your sanity check would send up a false positive.

Programmatically Verify an email message reached an exchange mail box

I have a job that runs which sends out emails to our users to which starts off a work flow process in our company. Periodically, a user will swear up and down that they didn't receive the email - though, when we go to the mail administrator to pull an exchange report, 10 times out of 10 it's in their deleted items. :P
I'd like to be able to programmatically verify that messages sent via .net C# (System.Net.Mail I think) reached the user's mail box.
It's exchange 2007 and all messages are internal.
You can't with System.Net.Mail. You'll have to dig through Exchange's APIs to determine if an email is present in someone's email account.
http://support.microsoft.com/kb/813349
Set an account for catching all bounce backs. In this way you will know which ones reached and which ones did not. This is the best way to ensure emails reached.
Alternatively you can add read reciepts via message headers(by setting the Disposition-Notification-To). but again, user can chose not to read it...
I see two ways to do what you want:
Send emails with "delivery confirmation" On (not "read receipt", this can be dismissed by the user as CoddeToGlory said). Then it's jut a matter of monitoring the mailbox that receives these confirmations via any way it's appropiate to you: Exchange Web Services, Outlook+COM or VBA, MAPI, ...
Use the powershell interface to Exchange and capture the output of Get-MessageTrackingLog looking for StoreDriver + Deliver events.

Categories

Resources