tags:

views:

318

answers:

3

I need to create a Windows service that can listen for SMTP.

When it receives an email I need to process it, and then forward it to my real SMTP server for sending proper.

Can anyone point me at any useful source code, libraries or tutorials on how I can get started doing this?

Seems like all I need is a simple TCP listener and message parser, then I can simply resend the message with the .NET SmtpClient API?

+1  A: 

You probably want to check this link. The article states that "The MailServerComponent implements POP3 and SMTP (core) servers. It Handles lowlevel POP3 and SMTP commands and raises events according to it. The MailServer service just handles MailServerComponent events and does mail retrieving and storing job.". It could, at least, serve as a starting point for you.

And you are right, you can implement you own (TCP) socket listener that handles and processes all required SMTP messages. Check the protocol specs here.

Audrius
+2  A: 

I don't know your entire requirements, but the IIS SMTP service can save incoming email to the /Drop directory. Rather than having to write a full blown TCP/IP service, you could just write a file monitoring service that monitors the /Drop directory for new emails, parses them, and performs your custom action on them.

dave wanta
oo this sounds promising, got any more info on how to do this?
Andrew Bullock
It's actually not that difficult. In the IIS SMTP admin interface, right-click on the SMTP virtual server, and list the domains you want to *accept* email for. Then, setup your DNS MX records to point to your IIS SMTP service IP. All incoming mail will be saved to the specified /Drop directory for those domains.
dave wanta
+1  A: 

Eric Daugherty has a C# email server on sourceforge. This will do the server. To forward the messages to another SMTP server the default System.Net.Mail.SmtpClient class can be used.

Or you write a custom transport binding element for WCF (joking).

Marc Wittke