tags:

views:

37

answers:

5

I had planned on using an open source SMTP server as a base and adding new features in to do whatever parsing I need and then send the response but I'm wondering if there is an even easier way to do this.

Is rolling my own SMTP server my best option or is there an easier way for me to do this?

I would prefer to use .NET to do this.

+2  A: 

Rolling your own SMTP server is an interesting challenge but not trivial. There are a number of Request for Comments (RFCs) that specify what an SMTP server needs to handle. Have a look at the Wikipedia article for some info on what RFCs apply, in particular RFC 5321.

Unless you have a lot of time on your hands or only need to implement a very small subset of the features I'd suggest using an open source server. There are some sample projects out there (e.g. CodeProject) that might be a good starting point if you want to build your own.

TLiebe
+1  A: 

Accomplishing this with the built-in .NET libraries is relatively simple.

The place to start would be to write a program to download the mail: here's a great example using POP3/C#.

Once you have that you can parse/store the e-mail contents using regex or whatever rules engine you're building and then use .NET smtp libaries to send out your responses.

Chris Pebble
A: 

It's very easy to send emails in .Net via SMTP, downloading and parsing them is a little bit more difficult but there's quite a few articles about writing POP3 clients so it's definitely doable. Or if you're willing to spend some money there are quite a few POP3 libraries to buy, but I've never tried any so I can't give any recommendations.

ho1
Sending emails is easy, but that's not what he's trying to do. He wants to *receive* mail from other servers, process them, then return replies.
dj_segfault
If you want to ding me that's fine, but I DID read the whole thing, and you specifically said you wanted to write/extend an SMTP server. Writing a POP3 client would only be useful if you already had an SMTP server and a POP3 server. So sorry if I misunderstood you, but I certainly read all of your question and ho1's response.
dj_segfault
@dj_segfault: No, he wrote that he was planning to extend an SMTP server but was asking if there was another alternative. However, I've misunderstood enough questions on here so I shouldn't complain too loudly. And I'll delete my comment above since it's not as friendly as it should be.
ho1
@ho1: Thank you.
dj_segfault
A: 

I don't think you want to deal with writing your own SMTP server because the conversation between the client and the server can be inconsistent and complex. Most SMTP servers let you specify a MDA (Mail Delivery Agent), like procmail, to deliver mail destined for users on that machine.

You can easily write procmail rules to pass emails through your program, which has the advantage of allowing you to call different scripts based on the content of the email headers and bodies, or write your script as an MDA itself.

dj_segfault
Interesting, I'll have to look into procmail.
Abe Miessler
A: 

Rolling your own SMTP server would be pretty much crazy. Why not connect to an existing SMTP server? Presumably the incoming email is coming from a server that also supports outgoing email.

Dan Puzey
I'm trying to figure out where I should perform actions on an inbound email. There is not an existing SMTP server that does what I need, that I why i am asking about using an open source SMTP as a base.
Abe Miessler
An SMTP server sends email. You can do whatever your processing is in your own code, and then use an existing SMTP server to send the resulting email. Or is there a reason that you can't?
Dan Puzey