Check out a free preview of the full Networking and Streams course

The "SMTP" Lesson is part of the full, Networking and Streams course featured in this preview video. Here's what you'd learn in this lesson:

By sending an email through localhost, James introduces SMTP, the protocol used to deliver email messages.


Transcript from the "SMTP" Lesson

>> Now that we've had some time to play around with HTTP servers and did a little bit with headers and netcat and curl, can talk a little bit about some other text based fun protocols like SMTP. SMTP is used to send emails. So, for example, we can send an email on our local SMTP daemon which on my system is running.

I don't know how common that is on Macs, but I don't know, give it a shot, maybe it'll work. If not, you can just see how it works on my machine. So we can send a message from whoever we want, because SMTP servers typically have no validation at all by default.

Although if you try to do this on a real SMTP server on the public internet, it's not going to work. So, it's kind of fun to do on localhost. So, here I can connect to localhost port 25. Email is just a simple text based protocol. It actually has a lot of commonality with HTTP.

So, it has things like status codes, it has things like in the body of messages, you have a similar idea to HTTP headers. It has similar kind of content mime system. So I can do, hello localhost. Let me get back message that's 200 category message that means okay, now I can send email from whoever I want.

So I send one from Sorry mail from, not fom 250 OK. So the server seems to be fine with this, even though just sending it from netcat locally. I can send rcpt to substack@localhost. So this is gonna send me an email locally. Accepted as well. Now you can send the data, the body of the email message with data commands.

And then by default, you type everything you want to type and then you hit a period. You type a period on a single line. So you hit period, Enter. And then that's like the end of the message. There's other ways of formatting it but this is the default way.

That's very old. So by default most email clients are going to interpret the first block just like HTTP is the headers. So one is called subject. You can also have things like different things in there. So, FAKE NEWS and two new lines just like HTTP and you're fired.

So there we go, it was sent. Okay, and we can quit. And now I have new mail on my system so I can type the mail command to read it. Here we go Get a message, you're fired. So this is all that it takes to send a message to an SMTP server.

Although in the real internet, the servers are very careful to check what IP address they're actually receiving the messages from so that they have some more verification than just accepting anything blindly. Which is actually how email used to work on the public internet back when everyone was an academic or worked for the military, I guess.

So just something kind of fun another text based protocol. That's, you can type out with netcat if you ever just want to poke around.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now