tags:

views:

384

answers:

5

Is there a way to peek or see a message before it hits the SMTP on IIS. This is not an Exchange Server, it's just running SMTP. I am trying to see if I can look at the message and then pass it to SMTP?

Thanks

Edit ~ Instead of adding another listner, I am wondering if there is a way to bind to the default SMTP listner and intercept the message then pass it on.

2nd Edit~ Ok, here is my problem. I have a spam filter in front of my exchange box, unfortunately (due to software design) the filter is limited when it comes to "Directory Harvesting Loookup". This is the process where the email addresses are checked if they exists in AD and the mail is dropped if they don't. My current filter drops the mail if one of the addresses does not exists in AD which is not good. I spoke with the vendor and there is nothing they can do at this time. I am looking put an app in front of this filter which would intercept (open, read, parse) the mail, validate the addresses, and then pass on the email to the filter for additional scanning. I'll then trun off this feature in their software. Don't get me wrong, their filter works great with this one exception which I must fix since I have tons of emails send to nonexistent users in my domain.

A: 

In .Net you can tell the SmtpClient to send email to a different folder than the SMTP service is monitoring. That way you could check each message, then move it to the real pickup folder. (See SmtpClient.PickupDirectory)

David
+2  A: 

You can write your own Proxy SMTP service that you connect to to send messages. You can forward all messages directly to your actual SMTP service and pass all responses back. Then you can evesdrop on all these messages and deal with them accordingly.

Might be a bit overkill for what you're after but it's fairly simple to code as you dont need to know anything about the protocol as all you're being is a proxy.

Robin Day
I am trying to inspect inbound message to an SMTP Server and then pass it on. Instead of adding another SMTP listner, I was hoping to just intercept the message first.
Saif Khan
+1  A: 

If you're using .NET 2.0 then you can log SMTP sessions to a file:

How do I create a log file of the SMTP session? (System.Net.Mail)

Updated:

Take a look at this question:

Testing SMTP with .net (Stack Overflow)

From your edit:

"I am wondering if there is a way to bind to the default SMTP listener and intercept the message then pass it on?"

...and from your comment below:

"I am looking to inspect the actual message before the SMTP gets it."

I'm not sure if you fully understand the SMTP protocol. SMTP messages aren't just monolithic fire-and-forget entities. SMTP is session based and there is a conversation between client and server, of which, the message is just a part. The tracing method (linked to above) will record the entire exchange between client and server and does intercept the whole message before passing it on. The alternative, a proxy or mock server, will still require your application to engage in the SMTP client/server exchange. The closest solution to your requirement would be to use something like Papercut which is linked to in the answer above.

Kev

Kev
I am looking to inspect the actual message before the SMTP gets it.
Saif Khan
I've edited my post and added my objective. Thanks again for your assistance.
Saif Khan
That completely changes the landscape then :)
Kev
A: 

IIRC, you can still write up event sinks for the IIS SMTP service (even though it's not full blown exchange). It's been many years since I've done this, but you may want to google for "exchange event sink" to see if that helps.

dave wanta
I've edited my post and added my objective. Thanks again for your assistance.
Saif Khan
A: 

Seems like a something like Ethereal will let you accomplish the sniffing portion of your request. Its not clear to me what you mean by "intercept" and "pass on". Do you want to filter some traffic or just delay traffic long enough for you to inspect before you pass it on, or both?

s_t_e_v_e
I've edited my post and added my objective. Thanks again for your assistance.
Saif Khan