View Full Version : implementing a mail server
hi all,
i am implementing a mail server(local), so the client and server , both are applications(i am not using any third party component or web browser), so how to proceed?
i read rfc 2821 (for SMTP), it states that all the communication will be command-responce based, but what does it mean. for eg,
server on connection send a message(int) , say WELCOME,
now should the client responde back or should the server first send a start of message intimation (like COMMAND_START) to client before sending WELCOME and end with ending intimation (like COMMAND_ENDED).
i know all the above stuff are not properly organised, but i am not able to get into the implimentation of the big picture, so need advise on all possible area and points,
waiting for replies
with thanks
dev
mlampkin
04-24-2003, 06:16 AM
It is 100% command / response... ok... so what does that mean? Probably easiest to give a quick example... try logging into a mail server by doing a telnet servername 25 and you should see something like:
220 softwarename SMTP etc. etc. etc.
There are two basic types of responses... single and multi-line ones... once connected, try typing the following:
HELO argh.com
The server should respond with something like
250 softwarename HELO [address] Please to meet you
Notice there is a text number, a space and then other human readable text... the space between the text number and the rest of the text means it is the last (and in this case only) line in the response...
To see a multi-line response type:
HELP
You will see something like:
214-sometext etc.
214-sometext etc.
etc. etc. etc.
214 some text
The dashes after the text number means that there are still more lines to the response... the last line of course has a space instead of a dash...
Not 100% sure if that answered your question(s) but hoepfully it will help you with understanding the rfc (it jumps around a bit)...
Michael
hello mlampkin,
thanks a lot, but some doubts remains,
- why is the number (like 250) in text form,
so should it be implemented using text itself, or can we use by directly sending the int( thats the reason why i was asking how to send an int over socket)
is it so that the whole of line (like - "250 softwarename HELO [address] Please to meet you ") is to be send together as a line,or 250 should be send as a number and then the text should follow?
and as a responce the reciver may send 250( all well), and here again should the 250 be send as a number or text? y? and what are the problems that may come up if done as sending int and text seperatly?
- can u further explain bout multi-line responce?
with thanks
dev
hi michael,
how can we understand that line for message has terminated? does more than 2 spaces means that the message has terminated?
dev
hi michael,
ok i got bout multilined responce, but tell me bout the digits that follow the text number? i got the following on HELP:-
214-2.0.0 This is sendmail version 8.11.6
214-2.0.0 Topics:
214-2.0.0 HELO EHLO MAIL RCPT DATA
214-2.0.0 RSET NOOP QUIT HELP VRFY
214-2.0.0 EXPN VERB ETRN DSN AUTH
214-2.0.0 STARTTLS
214-2.0.0 For more info use "HELP <topic>".
214-2.0.0 To report bugs in the implementation send email to
214-2.0.0 sendmail-bugs@sendmail.org.
214-2.0.0 For local information send email to Postmaster at your site.
214 2.0.0 End of HELP info
- are all text number (like 220) are of fixed length?(of 3?)
-now what does 2.0.0 in 214-2.0.0 means?
-if we take "214-2.0.0" as a single command, then how will it be different from "214" and how will it distinguse between a single line and multy lined responce?
- in multilined respose as above , are all the lines send together or as seperate lines,
- and how does the clinet responce to each line, i mean does it give individual ack to each line or to each responce or it doesnot give any responce, i can only see what the client gets, how can i see what the server gets?( i know , my project itself is what both parties do, and how),
so can u give a more bout the modalities/syntax/sementices or order of the whole interation from implementation point of view,
i am very thankfull to get this much,( i was totally clueless how and where to start, u gave me something, ) so if u can do reply,
with thanks
dev
hi michael,
i learned to use telnet and command of smtp to send mail, but in the mail from field i can use any name, so what is the surety that the mail i get from someone is send by himself?
dev
mlampkin
04-24-2003, 11:03 PM
Seems to be more questions about the leading numbers than anything else... so we'll cover that first...
For transmission, they are always sent as text... by both the client and the server... never as the raw (binary) number... so you have to do a string comparison or strtol (or similar) and then a comparison... for transmission use sprintf (or similar) to convert the number you want to send to text...
The numbers themselves must ALWAYS be three digits... no exceptions... that is explicitly stated (I know that w/o checking) in the rfc...
As for the question about data the server sends... the server should only send a "response" without a request from a client under two conditions... the first is when a client first logs in... the server will send a message saying welcome etc. etc. etc. ... the other is if the server institutes an inactivity timeout... this is NOT within spec but is often seen... where the server sends a goodby message and disconnects after a specifi amount of inactivity... In both of these cases, the client should NOT send a reponse...
For multi-line responses, simply check if the fourth character of a received line is a - and if so, there are more response lines... if a space character follows it then it is the last (and possibly only) line in the response... if it is any other character, then it is an inproper response...
As pertains to the "xxx-2.0.0 some text" responses... the xxx (numeric response) is what you should be parsing... for the most part, the text after the numbers (other than the trailing "-" or " " chars) are just meant to provide human readable information... and there is little to no standard on the format of that information... you should (conceivably) be able to write a client that completely ignored (most of) the text data...
Last but not least... yes, most servers will merrily act as though they will take your mail no matter what... the truth is though, unless they are completely open to relaying (a bad thing), they will check your source ip address and see if it is valid for sending mail from... if it is not, the server will send an email saying relaying not allowed (or similar)... if your system is on an allowed ip addr and you do give it a valid from address, then yes, you CAN spoof email... this is why folks added the various AUTH commands for SMTP (there are other rfcs covering this - I wouldn't worry about it until you have the core of your code working at 100% though)... which do require any connection to send a user name and pwd before allowing the transmission of mail...
Whew... I think that covered it all ;-)
Michael
hello michael,
thanks a lot,
well the only thing left out is bout the max length of a single line, that is how much can a line contain ?, and am i right that each line will be ended with a '\0' ?( i hope <crlf> is '\0', or is that to be implemented as text string of "crlf" ?
thanking you
dev
RobSeace
04-28-2003, 12:48 PM
CRLF == Carriage Return + Line Feed... Ie: "\r\n"...
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.