[nodejs] A node.js email server

703 views
Skip to first unread message

Terry Riegel

unread,
Jul 20, 2010, 2:48:15 PM7/20/10
to nod...@googlegroups.com
Hello,

I am just getting aquatinted with node.js. I was wondering if anyone has heard of or done some work on a simple email server with node.

I would like to set up an email to web system so that people with cell phones can email pictures to an address that will automatically update their blog.

Just wanted to ask here before I got to far down the path myself.

Thanks,

Terry Riegel

James Carr

unread,
Jul 20, 2010, 2:57:24 PM7/20/10
to nod...@googlegroups.com
I think you should do it even if it's already been done. The best case
scenario is you might wind up making one better than the rest and the
worst case scenario is you'll just learn a lot about node. :)

> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>
>

Marak Squires

unread,
Jul 20, 2010, 3:01:06 PM7/20/10
to nod...@googlegroups.com
we just use sendmail and http://github.com/marak/node_mailer, gets the basics done.

Renato Elias

unread,
Jul 20, 2010, 3:05:59 PM7/20/10
to nod...@googlegroups.com
Wow, it`s sound good =D

Terry Riegel

unread,
Jul 20, 2010, 3:13:24 PM7/20/10
to nod...@googlegroups.com
I am looking for something that will accept email.

I think I will take a stab at it. I am not looking to build a full featured email server just something that will accept connections and deal with what comes in.

I already have the echo server up and running :)

This should be a lot of fun.

Terry

Peter Griess

unread,
Jul 20, 2010, 3:34:08 PM7/20/10
to nod...@googlegroups.com
Something like http://lamsonproject.org/ for JavaScript would be fantastic.

Peter

Micheil Smith

unread,
Jul 20, 2010, 4:21:57 PM7/20/10
to nod...@googlegroups.com
There was a part of one of my projects where another developer was writing the server
variant, that project was node-smtp-client.

Although, do be wary and take note that doing email isn't an easy task.

Yours,
Micheil Smith
--
BrandedCode.com

Terry Riegel

unread,
Jul 20, 2010, 9:34:03 PM7/20/10
to nod...@googlegroups.com
I have the server running it will accept an email. It echos what comes in and what it sends to the console.

So far I can send any email to it from osx Mail and it thinks it is talking to a real server.

One thing that threw me was when the callback for incoming data triggered I assumed it would fire for every line coming in, but it received the whole body before firing. So instead of checking for the first three characters to be .\r\n I have to check the last three characters.

Also something interesting I discovered with Apples Mail program. It keeps the connection alive after sending the message for 1-2 minutes, then it issues the quit to close.

Looks like node.js will make this task extremely easy. Loving it so far!

Terry Riegel


On Jul 20, 2010, at 6:23 PM, talltyler <tall...@gmail.com> wrote:

> Are you planning on open-sourcing your work? I wouldn't mind helping
> with this project if so. I run a few mailing list that I would love to
> switch over to something that I have a little more programatic control
> of.

Micheil Smith

unread,
Jul 20, 2010, 11:23:24 PM7/20/10
to nod...@googlegroups.com
Hi Terry,

Hopefully you're implementing this as a module and to the RFC's on the
SMTP / IMAP protocols. In which case, it'd be great if you could release
the module as open-source for others to use.

Yours,
Micheil Smith
--
BrandedCode.com

Stephen Belanger

unread,
Jul 21, 2010, 12:11:49 AM7/21/10
to nod...@googlegroups.com
I would certainly appreciate an open-source email server. If one isn't made by someone else, I'll have to make one myself for work before too long. :)

Terry Riegel

unread,
Jul 21, 2010, 8:00:58 AM7/21/10
to nod...@googlegroups.com
Currently I am learning the node.js ropes so to speak so I don't have a lot of 'baggage' in what/how I have already done it. So I definitely can look at making it a module.

I do have a question about the net module. When a on data event fires the data may be multiple lines long. Is there a way to have it fire after each line? Otherwise I have to split and then go through each line at a time. If the event fired for each line I could avoid that and possibly save buffering resources.

Thanks,

Terry

Micheil Smith

unread,
Jul 21, 2010, 8:10:04 AM7/21/10
to nod...@googlegroups.com
Hi Terry,

Yes, you need to write your own parser for the data. I like to think that the one I'm using in
node-websocket-server is a good example of one, and when I work on node-smtp-client
again, I'll be reimplementing it's parser in a similar way.

Link: http://github.com/miksago/node-websocket-server/blob/development/lib/ws/connection.js#L369-403

Yours,
Micheil Smith
--
BrandedCode.com

Terry Riegel

unread,
Jul 21, 2010, 9:45:22 AM7/21/10
to nod...@googlegroups.com
Ok here is the code for my rudimentary email server. Currently it accepts connections from everywhere. It will go through the motions but the email is dumped upon completion.

Next up is the parsing phase. Can't wait :)
I would like to convert any non-utf encodings to utf-8 as it comes in. So I will have to look up charsets with node.

You can send an email to it currently. Just address it to...
WhateverYouW...@mailer.youbelong.net

The full source code is available here...
http://youbelong.net/pages/start/nodeSMTP/email.html

The source is the live copy of what I am actively developing and what the server is currently running. So depending on when you try the source may have changed. There is a little triangle in the page that would allow you to view the change history.


node.js is cool!

Terry

Terry Riegel

unread,
Jul 21, 2010, 9:47:15 AM7/21/10
to nod...@googlegroups.com
Also,

You can hammer at the server with telnet...

telnet beta.youbelong.net 25

Terry

Marak Squires

unread,
Jul 21, 2010, 10:51:09 AM7/21/10
to nod...@googlegroups.com
Cool Terry! Are you on github yet?

Aaron Heckmann

unread,
Jul 21, 2010, 11:11:33 AM7/21/10
to nod...@googlegroups.com
I noticed you're using your own implementation of String.prototype.trim which in available in V8 by default: http://wiki.github.com/ry/node/ecma-5mozilla-features-implemented-in-v8

Terry Riegel

unread,
Jul 21, 2010, 11:35:48 AM7/21/10
to nod...@googlegroups.com
Thanks, I removed it from my code.

RE: github, I do have an account but have never used a versioning system so I manually upload stuff. If this matures I'll start a project for it there.

Terry

Isaac Schlueter

unread,
Jul 21, 2010, 1:53:56 PM7/21/10
to nod...@googlegroups.com
On Wed, Jul 21, 2010 at 08:35, Terry Riegel <rie...@clearimageonline.com> wrote:
> If this matures I'll start a project for it there.

Oh no! Doing It Wrong!

"git init" should be the first thing you do for any project. Stop
what you're doing right now, install git, and read through one of the
many "basic getting started" tutorials out there.

Use it diligently, and after a few months, you'll wonder how you ever
lived without it, I promise. If nothing else, it makes it WAY easier
to get feedback on your code. I even track my dot-files and websites
content/configs in git, so that I can roll back any change that causes
a problem, and push the content between machines easily.

But git isn't really about all that stuff.

Git is an editor that you use to write the ongoing biography of your
program. It's not really about controlling versions, or pushing
between servers, or even collaboration, though it does make those
tasks much simpler. It's about tracking information in a low-impact
way.

*Now* is the time to start tracking your decisions, in real time, as
you're experimenting and trying things out. The un-mature project
benefits *most* from added meta information! What good is a biography
that doesn't cover one's childhood?

If git is indeed the first version control system you've ever used,
then I envy you, sir, for you have much less cruft to unlearn.

--i

Marak Squires

unread,
Jul 21, 2010, 2:01:19 PM7/21/10
to nod...@googlegroups.com
+5

i'll usually start with a nice readme file and a mocked up api implementation. then i'll send this stuff around to a few people to get feedback before i write any code.


--

Stephen Belanger

unread,
Jul 21, 2010, 2:02:27 PM7/21/10
to nod...@googlegroups.com
What he said. ^

After using git for a few projects in the past, I couldn't possibly live without it.

It gives you a backup of your code in the event that something goes horribly wrong with your computer. It gives you an easy way check what you changed last. Sometimes things break and you don't notice until you've left the project alone for weeks, or months even. It's much easier to track down if you can quickly find what you did last and fix it.

Version control is just a good habit to get into.


--

Mihai Călin Bazon

unread,
Jul 21, 2010, 2:16:12 PM7/21/10
to nod...@googlegroups.com
+1 for version control and +0.99(9) for Git ;-).

I'm rather new to Git but I must say it's great, particularly combined
with a powerful editor (Emacs) and a great add-on that knows how to
Git (It's Magit! [1]).

I've been happy with CVS for a while, then SVN for a while (definitely
wouldn't be happy with them now), then with Perforce. Currently I'm
happy with Mercurial but I must bow to the wonderfulness of Git and
I'm slowly moving my projects to it.

Anything is a lot better than no versioning at all, so whatever you
do, if you care about your code, and even if you don't, go for some
version control system.

Cheers,
-Mihai

[1] http://philjackson.github.com/magit/

--
Mihai Bazon,
http://mihai.bazon.net/blog

Ryan Gahl

unread,
Jul 21, 2010, 3:43:51 PM7/21/10
to nod...@googlegroups.com
I say use CVS first, then SVN, and for the heck of give SourceSafe a try... just so you can fully appreciate how awesome Git is.

Or just use git and live in blissful harmony with the universe.




2010/7/21 Mihai Călin Bazon <mihai...@gmail.com>

Terry Riegel

unread,
Jul 23, 2010, 3:08:40 PM7/23/10
to nod...@googlegroups.com
Thanks everyone for the nudge to get up and running with git. I have it installed and will be doing my first commit soon. I have a question regarding git. Is there a way to have a project that git can manage that has 2 distinct paths.

For example in my projects I have a PRIVATE and a PUBLIC tree structure.

the paths would look something like...

/path/to/cgi-bin/private/projects/emailserver
/path/to/httpdocs/projects/emailserver

All of my development tools use this structure to present to me a single view of both distinct paths, the stuff that needs to be public facing like images css files etc goes into the public site, and the private stuff contains my web app logic etc.

I can just git the private side, but it would be cool if git could also manage the public side too.

If anyone knows how this might be best managed I would appreciate some advise. If you think you understand what I am doing and know git can't do it then I would like to hear that also. If you think my workflow is all messed up feel free to advise, but I have 10 years of doing it this way so I may not take your advise.

Anyhow thanks for any ideas.

Terry

Terry Riegel

unread,
Jul 23, 2010, 4:48:53 PM7/23/10
to nod...@googlegroups.com
Ok Ok git is cool. Just created my second repository...

http://github.com/riegel/node.js-SMTP-server

Feedback welcome. Now on to finishing the code :)

Terry

Marak Squires

unread,
Jul 23, 2010, 4:54:53 PM7/23/10
to nod...@googlegroups.com
+1

protip : try to make your project names more concise. node-smtp? node-smtp-server ?

Micheil Smith

unread,
Jul 23, 2010, 5:07:15 PM7/23/10
to nod...@googlegroups.com
No, don't make the project name smaller, as if it's just a server, you should say so. Just like node-websocket-server,
node-websocket-client & node-smtp-client.

Anyway, good work :)

Yours,
Micheil Smith
--
BrandedCode.com

Terry Riegel

unread,
Jul 23, 2010, 5:56:46 PM7/23/10
to nod...@googlegroups.com
I hope everyone has patience with me as I am still trying to figure out this git business.

If I do this...
git push g...@github.com:riegel/node.js-SMTP-server.git
it works.

if I do this...
git push origin server
it fails with...
error: src refspec server does not match any.
error: failed to push some refs to 'g...@github.com:riegel/node.js-SMTP-server.git'


I thought this command...
git remote add origin g...@github.com:riegel/node.js-SMTP-server.git

setup the thing "origin" so that I could just do "push origin server" but I am getting an error. any ideas?

There must be a concept I am not getting.

Thanks,

Terry

Elijah Insua

unread,
Jul 23, 2010, 6:15:48 PM7/23/10
to nod...@googlegroups.com
On Fri, Jul 23, 2010 at 5:56 PM, Terry Riegel <rie...@clearimageonline.com> wrote:
if I do this...
git push origin server
it fails with...
error: src refspec server does not match any.
error: failed to push some refs to 'g...@github.com:riegel/node.js-SMTP-server.git'

try a 'git push origin master'

Terry Riegel

unread,
Jul 23, 2010, 6:17:13 PM7/23/10
to nod...@googlegroups.com
I feel like an idiot.

thanks Elijah


Marak Squires

unread,
Jul 23, 2010, 6:17:26 PM7/23/10
to nod...@googlegroups.com
yeah i mean, unless you have a branch called "server" you should specify the default git branch , "master"

i'm not sure where the word "server" came from in your line of thinking

--

Terry Riegel

unread,
Jul 23, 2010, 7:00:26 PM7/23/10
to nod...@googlegroups.com
I had manually transcribed it from a printout and must have typed server instead of master ... after that it was all cut and paste.

Terry

Stephen Belanger

unread,
Jul 23, 2010, 7:03:43 PM7/23/10
to nod...@googlegroups.com
We all have our brainless moments. When I first tried svn, I tried to commit some files, forgetting that I hadn't yet actually initialized the repository yet. :P

Marak Squires

unread,
Jul 23, 2010, 8:46:41 PM7/23/10
to nod...@googlegroups.com
Terry -

If you don't have one already, check out this git cheat sheet, usually helps me a lot.

Neville Burnell

unread,
Jul 23, 2010, 8:50:04 PM7/23/10
to nodejs
don't forget to declare copyright and your license

On Jul 24, 10:46 am, Marak Squires <marak.squi...@gmail.com> wrote:
> Terry -
>
> If you don't have one already, check out this git cheat sheet, usually helps
> me a lot.
>
> http://cheat.errtheblog.com/s/git
>
> On Fri, Jul 23, 2010 at 7:03 PM, Stephen Belanger <cyruzdr...@gmail.com>wrote:
>
>
>
> > We all have our brainless moments. When I first tried svn, I tried to
> > commit some files, forgetting that I hadn't yet actually *initialized* the
> > repository yet. :P
>
> > On Fri, Jul 23, 2010 at 4:00 PM, Terry Riegel <rie...@clearimageonline.com
> > > wrote:
>
> >> I had manually transcribed it from a printout and must have typed server
> >> instead of master ... after that it was all cut and paste.
>
> >> Terry
>
> >> On Jul 23, 2010, at 6:17 PM, Marak Squires wrote:
>
> >> yeah i mean, unless you have a branch called "server" you
> >> should specify the default git branch , "master"
>
> >> i'm not sure where the word "server" came from in your line of thinking
>
> >> On Fri, Jul 23, 2010 at 6:15 PM, Elijah Insua <tmp...@gmail.com> wrote:
>
> >>> On Fri, Jul 23, 2010 at 5:56 PM, Terry Riegel <
> >>> rie...@clearimageonline.com> wrote:
>
> >>>> if I do this...
> >>>> git push origin server
> >>>> it fails with...
> >>>> error: src refspec server does not match any.
> >>>> error: failed to push some refs to '...@github.com:
> >>>> riegel/node.js-SMTP-server.git'
>
> >>> try a 'git push origin master'
>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups
> >>> "nodejs" group.
> >>> To post to this group, send email to nod...@googlegroups.com.
> >>> To unsubscribe from this group, send email to
> >>> nodejs+un...@googlegroups.com<nodejs%2Bunsu...@googlegroups.com>
> >>> .
> >>> For more options, visit this group at
> >>>http://groups.google.com/group/nodejs?hl=en.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "nodejs" group.
> >> To post to this group, send email to nod...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> nodejs+un...@googlegroups.com.
> >> For more options, visit this group at
> >>http://groups.google.com/group/nodejs?hl=en.
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "nodejs" group.
> >> To post to this group, send email to nod...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> nodejs+un...@googlegroups.com<nodejs%2Bunsu...@googlegroups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/nodejs?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "nodejs" group.
> > To post to this group, send email to nod...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > nodejs+un...@googlegroups.com<nodejs%2Bunsu...@googlegroups.com>
> > .

Neville Burnell

unread,
Jul 23, 2010, 8:51:34 PM7/23/10
to nodejs
> don't forget to declare copyright and your license

that would be in the Readme.MD, not the code.

Marak Squires

unread,
Jul 23, 2010, 8:52:02 PM7/23/10
to nod...@googlegroups.com
also, don't forget to bring a towel!

Elijah Insua

unread,
Jul 23, 2010, 11:18:46 PM7/23/10
to nod...@googlegroups.com
if you don't remember, the licensing fiasco was destroyed when the .flf parser was "white roomed" and re-build as asciimo.

Marak Squires

unread,
Jul 24, 2010, 12:05:01 AM7/24/10
to nod...@googlegroups.com
>.<

Elijah Insua

unread,
Jul 24, 2010, 12:37:06 AM7/24/10
to nod...@googlegroups.com
wow, sorry about that. I may actually be retarded.

Michael Jackson

unread,
Jul 26, 2010, 9:30:55 AM7/26/10
to nod...@googlegroups.com
You can find an excellent example of an email parser in Python's email
module. In the 3.1.2 source you can find it in Lib/email.

http://www.python.org/download/

Email is a complicated beast, probably because it has been around for
ages and there are thousands of different implementations out there.
If you try to roll your own parser from scratch it will either a) take
you a very long time or b) be so full of bugs that it won't be useful
in real-world scenarios. A couple of things I like about Python's
email parser:

1) It's very forgiving. When dealing with email you need to be as
lenient as possible. If you read through the email/mime RFC's, they
talk about being forgiving all over the place. For example, section
2.1.1 of RFC 2822 suggests that email messages should not contain more
than 78 characters per line (plus the CRLF), but that they may contain
up to 998. A good email parser should be robust enough to accept
either one. This is just one small example.

2) It's a feed-style parser. This means that you can stream data to it
instead of buffering the whole message before you begin the parse. As
you probably know, this is what Node is all about. We prefer to stream
everything in Node to keep it as fast as possible and to keep the
memory footprint small.

Anyways, if you want a great example to follow (especially for Node),
there it is. The code is already there, so it should be relatively
easy to do a port.

Michael

--
Michael Jackson
http://mjijackson.com
@mjijackson

On Wed, Jul 21, 2010 at 7:45 AM, Terry Riegel
<rie...@clearimageonline.com> wrote:
> Ok here is the code for my rudimentary email server. Currently it accepts connections from everywhere. It will go through the motions but the email is dumped upon completion.
>
>
>
> Next up is the parsing phase. Can't wait :)
> I would like to convert any non-utf encodings to utf-8 as it comes in. So I will have to look up charsets with node.
>
>
>
> You can send an email to it currently. Just address it to...
> WhateverYouW...@mailer.youbelong.net
>
>
>
> The full source code is available here...
> http://youbelong.net/pages/start/nodeSMTP/email.html
>
>
>
> The source is the live copy of what I am actively developing and what the server is currently running. So depending on when you try the source may have changed. There is a little triangle in the page that would allow you to view the change history.
>
>
> node.js is cool!
>
>
>

> Terry
>
>
>
>


> On Jul 21, 2010, at 8:10 AM, Micheil Smith wrote:
>
>> Hi Terry,
>>
>> Yes, you need to write your own parser for the data. I like to think that the one I'm using in
>> node-websocket-server is a good example of one, and when I work on node-smtp-client
>> again, I'll be reimplementing it's parser in a similar way.
>>
>> Link: http://github.com/miksago/node-websocket-server/blob/development/lib/ws/connection.js#L369-403
>>

>> Yours,
>> Micheil Smith
>> --
>> BrandedCode.com
>>

>> On 21/07/2010, at 10:00 PM, Terry Riegel wrote:
>>
>>> Currently I am learning the node.js ropes so to speak so I don't have a lot of 'baggage' in what/how I have already done it. So I definitely can look at making it a module.
>>>
>>> I do have a question about the net module. When a on data event fires the data may be multiple lines long. Is there a way to have it fire after each line? Otherwise I have to split and then go through each line at a time. If the event fired for each line I could avoid that and possibly save buffering resources.
>>>
>>> Thanks,
>>>

>>> Terry
>>>
>>>


>>> On Jul 21, 2010, at 12:11 AM, Stephen Belanger wrote:
>>>
>>>> I would certainly appreciate an open-source email server. If one isn't made by someone else, I'll have to make one myself for work before too long. :)
>>>>
>>>> On Tue, Jul 20, 2010 at 8:23 PM, Micheil Smith <mic...@brandedcode.com> wrote:
>>>> Hi Terry,
>>>>
>>>> Hopefully you're implementing this as a module and to the RFC's on the
>>>> SMTP / IMAP protocols. In which case, it'd be great if you could release
>>>> the module as open-source for others to use.
>>>>

>>>> Yours,
>>>> Micheil Smith
>>>> --
>>>> BrandedCode.com
>>>>

>>>> On 21/07/2010, at 11:34 AM, Terry Riegel wrote:
>>>>
>>>>> I have the server running it will accept an email. It echos what comes in and what it sends to the console.
>>>>>
>>>>> So far I can send any email to it from osx Mail and it thinks it is talking to a real server.
>>>>>
>>>>> One thing that threw me was when the callback for incoming data triggered I assumed it would fire for every line coming in, but it received the whole body before firing. So instead of checking for the first three characters to be .\r\n I have to check the last three characters.
>>>>>
>>>>> Also something interesting I discovered with Apples Mail program. It keeps the connection alive after sending the message for 1-2 minutes, then it issues the quit to close.
>>>>>
>>>>> Looks like node.js will make this task extremely easy. Loving it so far!
>>>>>
>>>>> Terry Riegel
>>>>>
>>>>>
>>>>> On Jul 20, 2010, at 6:23 PM, talltyler <tall...@gmail.com> wrote:
>>>>>
>>>>>> Are you planning on open-sourcing your work? I wouldn't mind helping
>>>>>> with this project if so. I run a few mailing list that I would love to
>>>>>> switch over to something that I have a little more programatic control
>>>>>> of.
>>>>>>
>>>>>> On Jul 20, 2:48 pm, Terry Riegel <rie...@clearimageonline.com> wrote:
>>>>>>> Hello,
>>>>>>>
>>>>>>> I am just getting aquatinted with node.js. I was wondering if anyone has heard of or done some work on a simple email server with node.
>>>>>>>
>>>>>>> I would like to set up an email to web system so that people with cell phones can email pictures to an address that will automatically update their blog.
>>>>>>>
>>>>>>> Just wanted to ask here before I got to far down the path myself.
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> Terry Riegel
>>>>>

Terry Riegel

unread,
Jul 26, 2010, 2:26:43 PM7/26/10
to nod...@googlegroups.com
Thanks for the advise, I'll get a copy.

Terry

Reply all
Reply to author
Forward
0 new messages