Question

Just out of curiosity and some experimentation of mine, i'd like to know what it would take to build an STMP client on the browser. A few years ago this was nearly impossible but now almost every browser in the planet seems to have implemented web sockets so i can only assume this should be possible. I'd like to know some exact details on how to implement this without digging through the RFC for SMTP (RFC-2821) and confuse myself even more. I have learnt over the years how to work with the HTTP protocol from sniffing HTTP Packets and trying to understand the protocol from what the web browser is sending and what my server is expecting and I was wondering if i could use the same technique to demystify the SMTP protocol. I also remember some 10 years ago, i used to send emails from windows command prompt via telnet using free publicly available smtp relay servers and i'm sure i can still remember a few commands. How do i mesh all these together...say in javascript.

I'll be happy to know if anyone has tried this and is willing to share some knowledge on this.

Was it helpful?

Solution

You will need a protocol bridge between WebSockets and normal TCP sockets such as websockify (disclaimer: I created websockify). The websockify project includes a simple telnet (wstelnet.html) and irc (wsirc.html) client (from the same era and similar in form to SMTP). You should be able to modify one of those to accomplish what you need. For example, if you point websockify at your SMTP server and then load wstelnet.html and connect to the websockify instance then you can manually interact with the SMTP server (just like you did 10 years ago). From that starting point you can begin automating parts of the interaction.

OTHER TIPS

You cannot do this with WebSockets, because they are not plain sockets, but live inside an existing HTTP connection, have there own framing etc. And probably your browser also forbids accessing the SMTP ports from inside the browser for security reasons.

See What's the main difference between bidirectional and directional sockets? for the difference between normal TCP connections and WebSockets.

Mailsac has a SMTP-to-web-socket API documented here, though it is paid. Messages are already parsed into JSON, but the original raw data is buffered and included in the JSON.

Disclosure: I work on Mailsac.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top