Hey everyone and welcome back. Now in the previous nugget we had laid out our plans for this
skill and we decided that the very first thing that we're going to talk about and tackle
is this email server configuration. Now before we actually begin the actual configuration
itself what we're going to do is talk about some of the key components at play here with
respect to email. Now one thing we must know is that email is largely or should I say critically
dependent on something called SMTP. This is the simple mail transfer protocol. Now this
runs over port 25 by default so if you happen to have some type of firewall in play be aware
that if you block this port you could be blocking your email services. Now with respect to SMTP
this is what actually enables how email can be sent and how email can be stored. Now with
respect to email there are some particular components to this architecture that we really
have to be aware of. The first one is called the MUA. Now this stands for the mail user
agents and this will basically be a particular program that we can use as a client to actually
create our own email messages. Now there are many different MUAs available in the Linux world. One
we will get to look at later on within this skill is the Thunderbird client. This is very well
known within the world of Linux. Another very important component is the MTA. Now with respect
to the MTA what this is going to do is going to actually take in the messages from the MUA,
the mail user agent and once it has ingested these messages it's going to send it over to the
corresponding mail server that is the target. Now there are different MTAs. One that we're going
to be looking at in this skill right here. In fact very shortly within this nugget is one called
Postfix. So really think about it. The MUA can talk to an MTA which is a server and that can pass
on messages to another MTA. And the last component is the MDA. This is the mail delivery agent. So
what this is going to do is it's going to take the information stored on the MTA and transfer it
to the local mail spool. So really I can just draw this. We could have an MUA sending a message
to an MTA server which then fires that off to the relevant MTA server based on a particular
destination whatever it may be and the recipient user they could have an MDA which would actually
pull that message in from this MTA. Now one thing to note with respect to email we have these
different protocols. We have the POP3 protocol and we have the IMAP protocol. Now the way the emails
happen to be retrieved are dependent on the type of protocol we happen to use. Let's say for example
that we had some type of email server and this is where all our emails were coming in and being
stored. Now us here as a client just on a regular computer if we were using POP3 we would contact
our email server using POP3 and we would actually download the contents of our email onto our local
machine. Okay so think about it. The messages go to the email server. We contact the email using
POP3 and we effectively get a local copy on our physical machine right here. This means that the
server up here can or may delete those emails after we have downloaded them and save up the space
on the email server. Now the reality is this is more of an older approach. Instead what more often
happens now is we use IMAP. So think about it like this. We have the PC wanting to read the emails.
The emails are stored on the email server. If we use IMAP we just simply consult the email server
and we read the data directly from the server so we don't actually download the local copy to our
machine. We read the data from the server and present it on our PC and this is how basically
modern email works. Things like Gmail when you happen to grab your laptop and you log into your
Gmail you're contacting the server and it's being displayed on your local machine but the emails
aren't actually stored there. Instead they are still stored within the email server. That means
that if you happen to grab another laptop and log in to your email account you can still read
the same emails because they are still on the same server. They've not been transferred and
locally downloaded onto a particular machine. Everything is handled by the central server.
So these are the some of the main components with respect to email servers that we want to be
aware of. So like I say we were talking about particular MTAs. The MTA we happened to mention
was one called PostFix. Now PostFix just as an aside actually builds upon and is backwards
compatible with the older implementation called Sendmail. Now Sendmail was the OG. This was the
first main one on the scene that made a splash but it is notoriously complex and it is a little
bit insecure. So PostFix seeks to address some of these problems and make the process a little bit
more secure and a little bit simpler. So that is what we're going to be focusing on. So what I'm
going to say is Sudo app to install PostFix as well as something called Mail Utils. So if I hit
Y and Enter that should begin the installation. What I want to do here is to specify the type
of configuration I want. I'm going to specify an internet site. Now the system mail name you can
specify whatever it is you so wish. I'll just type in something like say ipv0-test.com and hit tab
and OK. And PostFix should begin installation or complete installation should I say. Okay so let's
go into the Etsy directory. I will do an LS. Now we should actually have a file called PostFix
which we actually do or rather should I say a directory that should be. So we go into the
directory and within here the main configuration file is one called main.cf. So really try to
remember this location. Etsy PostFix main.cf. Let's go in and have a look at this file then. So we'll
go in and say main.cf hit Enter. Now within here we're going to see a whole bunch of different
information. We can see how we can configure our SMTP banner which will populate our host
name using a variable value and the mail name. If we scroll on down we see a lot of information
relating to encryption i.e. transport layer security but further down this is really where we
want to be focusing on. So we can specify our host name which is system. In this case here if we
scroll on up this is the value here that's going to be populated my host name. In my case it will
be system. Scroll back down. We can see things such as the aliases. Now aliases are very very
useful. What this means is that we can ultimately alias a particular user so that mail for that
user can be redirected to another user. So a good example of this would be taking an alias or rather
specifying an alias within this particular file that is the Etsy aliases file and we could map
the root user to my local account of IPv0 for example. So if I wanted to check the emails that
were sent to the root user without having to change accounts i.e. without having to log in as the root
user I could actually just have any mail that is sent to the root user relayed to my local account
and still read them. Now my destination here these are all the locations specified here. So what this
means is that if the server happens to get any emails for any of the addresses that you see here
the server is going to keep them and deliver it to the local user. So if I send a message to
at localhost for example it will be for my local user here. Now one thing to note here is that we
have this configuration for relay host this is left blank. I just want to have a word of warning
that you probably and I should say strongly want to leave this as blank. The reason being is that
this could potentially compromise your system and that your server could ultimately be targeted to
really spam messages. So quite honestly if you do not know what you're doing with this I really
really would leave this blank. So now that we know that our main configuration file is this one right
here main.cf and we are aware of our aliases and destinations so on so forth. Let's begin doing some
basic testing of our mail service. So what I'm going to do here is I'm just going to exit out
and I will clear the screen. So let me show you how we can actually use this mail service if I just
see mail and say dash s for the subject matter. So I will just give this the subject matter of
hello world. Now realistically I could send this email out into the big bad world. So I actually
have a little test account called johnredtestatoutlook.com. Now if my local settings were configured
correctly I had a reputable domain name and not just ipv0 at system which looks kind of fishy.
I could send this off like I say if I enter now cc I don't want to add anyone in. I would just say
this is just some tests that will fail sad face. Now to end the message you might have to press
ctrl d. In my case I actually have to press ctrl shift d and with that the mail will be sent off
but the reality is given that my domain is a little bit dodgy this is going to fail it's going
to be rejected by the outlook servers. If I happen to issue the command mail we can actually see here
this is an undelivered mail returned to sender and a hit enter. Now do not despair like I say if
my domain was configured correctly and I really had an ipv0.com address or whatever it may be
then this configuration would work just fine but for the purposes of our little testing
do not worry about that at all. What we're now going to do is to try to test an email
by sending it to another account on this system. So what I will do is I will say mail dash s and
I'll maybe say hey there admin that will be the subject matter and what I will do is I will target
the root on the local host which is this machine right here. So if I hit enter cc I don't want to
add anyone in and I'll just say hello mr. Root this is John. I will press control shift D. Now if I
happen to hit the mail command here notice there is no mail for ipv0 that is because ipv0 was the
sender of this mail and the recipient should be the root account. So what I'm going to do is I'm
going to change into my super user which is now the root account. If I hit the mail command now
see we actually do have a message for the root account and we can see the subject here is hey
there admin we can see the sender was ipv0 if I hit enter we can actually see the contents of that
message. Now if I wanted to hit enter again we can see there's no more messages and now if I just
change back to ipv0 once again what I'm now going to do is I'm going to modify my aliases file remember
we talked about that so I'll go into the etse directory and then aliases again remember this
location very very important we can actually see here there already is an aliase configured meaning
that if we happen to send a message to quote unquote postmaster it's actually going to be sent to
the root account. To check this out if I just go back out here and I say mail s hey postmaster
and I address it to the postmaster of localhost I'll just say hey p.m for postmaster control
shift d if I say mail again no mail for ipv0 but if I go into my super user and I say mail now
notice here we're in the root accounts for here and we have received the message that was directed
to postmaster so postmaster has been relayed to the root account instead. Now check this out if I
just say d to delete this and q to quit what I'm going to do here is I will go back into ipv0 and I
will say sudo nano I'll go into the etse aliases once again and I'm going to add another piece of
information I'm going to see the root account should go to ipv0 now think about this we actually have
a chain going on right here if someone sends a message to postmaster it's going to be targeted
for root however because it's now targeted for root root is now mapping to ipv0 so ultimately
whenever someone sends a message to postmaster it's really going to go to ipv0 which is my local
account check this out then okay very very important now that we have modified this aliases
file it will not take effect just yet what I've got to do is issue this command sudo new aliases
now this is very very important we have to understand that the etse aliases file will not
be updated it will not take effect until this particular command is issued so if I hit enter now
check this out like I say in our aliases we send to postmaster postmaster goes to root root goes to
ipv0 so let's try this out then we will say mail s and we'll just say I love donuts and we'll send
this to postmaster at localhost and the message will just be just letting you know I love donuts
not sure why the postmaster would have to know this information but nevertheless let's go with it
ctrl shift d now who do you think is going to get this message then let's first try the super
user so we are now the root account let's see if the root account has this message the I love
donuts message is not there so if I press q to quit spot I change into ipv0 or rather that should be
substitute user ipv0 so I'm now ipv0 clear the screen I now say mail check this out it's only ipv0
who got that message and I can hit enter and we can actually see the contents of the email right
here so notice it was originally sent to postmaster which would have been relayed to the root but it
didn't actually go into the root account the root account automatically just passed it on via the alias
to ipv0 so really that is us for our basic introduction into using postfix so really we
want to be remembering that it's a postfix main dot cf configuration file we also want to remember
that we can create aliases in the etsy aliases file and if we want those changes to actually take
place we must use the new aliases command but for now as we can see here we are reading our files
we want to see a better way how we can actually manage our local mail service and well that's
what we're talking about in the very next nugget so I hope this has been informative for you and
I'd like to thank you for viewing