Hello

I have been set a task to myself build a "Local SMTP Server" as the product found on this URL: http://www.softaward.com/1036.html

I have googled around but cant find any code of how to do this.
The thing is that I use the SmtpClient Class and now in this code will set "localhost" as the SMTP Server.

But in order to be able to do this, I have to code my own "Local SMTP Server"...
How can I begin to do this, perheps there are any code to start out with etc.

I will be happy for guidance of how to begin. (I know how to send email using the SmtpClient Class)

Ok, you will need to look up the SMTP Protocol.

RFC1123 will help you get started. Also, please read the other related RFC documents.

An SMTP Server is simply a socket server that uses a specific message protocol to authenticate, send and relay mail messages.


So if you really want to take the "baby steps" so to speak, you will need to look up Sockets.

Thanks Ketsuekiame,

I have checked the documentation and will continue to read it. But I beleive I will need to understand some codingbasics of this is working.

What I first already know how to do is to send an email with the SmtpClient Class.
Here you will specify a server like this:
SmtpClient smtp = new SmtpClient("localhost");

I have seen in Local SMTP server documentation that you in this code put "localhost" to communicate with that particular SMTP server.

So let say that this code is OK now!

What now is needed is to code this SMTP server that simply is a socket server.

If I understand correct, it will work in this way:
SmtpClient code will send email to ----> Socket server that really do the send of the email to recepient ?

So this socket server must "listen" for an incoming message from the SmtpClient code and be able to send.

I have googled: "System.Net.Sockets.TcpClient" and find many different examples and do not know wich and what is relevant to be able to catch the message from SmtpClient code and send the email to recipeint.

I think this is quite difficult and then it could be good to have a "straight forward example" to easier understand.

I beleive this is what should happen:
(SmtpClient send email to ---> Listening socket server ---> Send Email to recepient)

Ok, from your reply I'm guessing you want to use C# and not C++. I've flagged your post so that it will get moved.

Back to the matter at hand, you're misunderstanding what I'm saying.

Yes .Net has a handy SmtpClient class which can communicate with an SMTP Server. The problem is that it does so using the SMTP Protocol. I have linked you to the protocol and it is up to you to write the server for it.

If you want to google for source code for an SMTP Server feel free. But if you actually want to learn, I suggest you start from scratch, learn the RFC and protocol and create the server yourself.

At a basic level, the SmtpClient connects to the server through a socket, sends a series of handshake commands and then another series of commands to build the message.

The SMTP Server, once it obtains the message, attempts to connect to connect to the mail server of the domain it's been given. It then uses the same protocol to say "hey I've got a message for you" and you hand it off to that server.

It's "easy" but not "simple"

Okay, Thanks Ketsuekiame,

I will try to understand this better then and start reading the documentations and take it step by step from there and see how I can figure this out.

Thanks for help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.