1
00:00:00,000 --> 00:00:17,620
Hey everyone and welcome back. Now in the previous nugget we had laid out our plans for this

2
00:00:17,620 --> 00:00:22,460
skill and we decided that the very first thing that we're going to talk about and tackle

3
00:00:22,460 --> 00:00:27,580
is this email server configuration. Now before we actually begin the actual configuration

4
00:00:27,579 --> 00:00:31,779
itself what we're going to do is talk about some of the key components at play here with

5
00:00:31,779 --> 00:00:38,619
respect to email. Now one thing we must know is that email is largely or should I say critically

6
00:00:38,619 --> 00:00:45,500
dependent on something called SMTP. This is the simple mail transfer protocol. Now this

7
00:00:45,500 --> 00:00:51,939
runs over port 25 by default so if you happen to have some type of firewall in play be aware

8
00:00:51,939 --> 00:00:59,899
that if you block this port you could be blocking your email services. Now with respect to SMTP

9
00:00:59,899 --> 00:01:05,739
this is what actually enables how email can be sent and how email can be stored. Now with

10
00:01:05,739 --> 00:01:10,700
respect to email there are some particular components to this architecture that we really

11
00:01:10,700 --> 00:01:19,459
have to be aware of. The first one is called the MUA. Now this stands for the mail user

12
00:01:19,500 --> 00:01:25,579
agents and this will basically be a particular program that we can use as a client to actually

13
00:01:25,579 --> 00:01:31,859
create our own email messages. Now there are many different MUAs available in the Linux world. One

14
00:01:31,859 --> 00:01:38,060
we will get to look at later on within this skill is the Thunderbird client. This is very well

15
00:01:38,060 --> 00:01:45,219
known within the world of Linux. Another very important component is the MTA. Now with respect

16
00:01:45,379 --> 00:01:52,019
to the MTA what this is going to do is going to actually take in the messages from the MUA,

17
00:01:52,019 --> 00:01:58,500
the mail user agent and once it has ingested these messages it's going to send it over to the

18
00:01:58,500 --> 00:02:04,539
corresponding mail server that is the target. Now there are different MTAs. One that we're going

19
00:02:04,539 --> 00:02:09,539
to be looking at in this skill right here. In fact very shortly within this nugget is one called

20
00:02:09,699 --> 00:02:17,939
Postfix. So really think about it. The MUA can talk to an MTA which is a server and that can pass

21
00:02:17,939 --> 00:02:27,819
on messages to another MTA. And the last component is the MDA. This is the mail delivery agent. So

22
00:02:27,819 --> 00:02:35,139
what this is going to do is it's going to take the information stored on the MTA and transfer it

23
00:02:35,139 --> 00:02:41,619
to the local mail spool. So really I can just draw this. We could have an MUA sending a message

24
00:02:41,619 --> 00:02:48,739
to an MTA server which then fires that off to the relevant MTA server based on a particular

25
00:02:48,739 --> 00:02:54,619
destination whatever it may be and the recipient user they could have an MDA which would actually

26
00:02:54,619 --> 00:03:02,259
pull that message in from this MTA. Now one thing to note with respect to email we have these

27
00:03:02,340 --> 00:03:08,539
different protocols. We have the POP3 protocol and we have the IMAP protocol. Now the way the emails

28
00:03:08,539 --> 00:03:15,219
happen to be retrieved are dependent on the type of protocol we happen to use. Let's say for example

29
00:03:15,219 --> 00:03:20,819
that we had some type of email server and this is where all our emails were coming in and being

30
00:03:20,819 --> 00:03:29,659
stored. Now us here as a client just on a regular computer if we were using POP3 we would contact

31
00:03:29,780 --> 00:03:37,060
our email server using POP3 and we would actually download the contents of our email onto our local

32
00:03:37,060 --> 00:03:43,219
machine. Okay so think about it. The messages go to the email server. We contact the email using

33
00:03:43,219 --> 00:03:49,659
POP3 and we effectively get a local copy on our physical machine right here. This means that the

34
00:03:49,659 --> 00:03:56,419
server up here can or may delete those emails after we have downloaded them and save up the space

35
00:03:56,539 --> 00:04:03,060
on the email server. Now the reality is this is more of an older approach. Instead what more often

36
00:04:03,060 --> 00:04:09,299
happens now is we use IMAP. So think about it like this. We have the PC wanting to read the emails.

37
00:04:09,299 --> 00:04:17,259
The emails are stored on the email server. If we use IMAP we just simply consult the email server

38
00:04:17,259 --> 00:04:22,939
and we read the data directly from the server so we don't actually download the local copy to our

39
00:04:22,980 --> 00:04:29,339
machine. We read the data from the server and present it on our PC and this is how basically

40
00:04:29,339 --> 00:04:34,779
modern email works. Things like Gmail when you happen to grab your laptop and you log into your

41
00:04:34,779 --> 00:04:40,500
Gmail you're contacting the server and it's being displayed on your local machine but the emails

42
00:04:40,500 --> 00:04:46,500
aren't actually stored there. Instead they are still stored within the email server. That means

43
00:04:46,500 --> 00:04:52,339
that if you happen to grab another laptop and log in to your email account you can still read

44
00:04:52,379 --> 00:04:57,699
the same emails because they are still on the same server. They've not been transferred and

45
00:04:57,699 --> 00:05:03,539
locally downloaded onto a particular machine. Everything is handled by the central server.

46
00:05:03,539 --> 00:05:07,939
So these are the some of the main components with respect to email servers that we want to be

47
00:05:07,939 --> 00:05:15,139
aware of. So like I say we were talking about particular MTAs. The MTA we happened to mention

48
00:05:15,139 --> 00:05:21,699
was one called PostFix. Now PostFix just as an aside actually builds upon and is backwards

49
00:05:21,740 --> 00:05:28,379
compatible with the older implementation called Sendmail. Now Sendmail was the OG. This was the

50
00:05:28,379 --> 00:05:34,300
first main one on the scene that made a splash but it is notoriously complex and it is a little

51
00:05:34,300 --> 00:05:39,339
bit insecure. So PostFix seeks to address some of these problems and make the process a little bit

52
00:05:39,339 --> 00:05:44,659
more secure and a little bit simpler. So that is what we're going to be focusing on. So what I'm

53
00:05:44,659 --> 00:05:51,579
going to say is Sudo app to install PostFix as well as something called Mail Utils. So if I hit

54
00:05:51,779 --> 00:05:57,740
Y and Enter that should begin the installation. What I want to do here is to specify the type

55
00:05:57,740 --> 00:06:03,579
of configuration I want. I'm going to specify an internet site. Now the system mail name you can

56
00:06:03,579 --> 00:06:12,459
specify whatever it is you so wish. I'll just type in something like say ipv0-test.com and hit tab

57
00:06:12,459 --> 00:06:18,939
and OK. And PostFix should begin installation or complete installation should I say. Okay so let's

58
00:06:19,019 --> 00:06:25,259
go into the Etsy directory. I will do an LS. Now we should actually have a file called PostFix

59
00:06:25,259 --> 00:06:29,620
which we actually do or rather should I say a directory that should be. So we go into the

60
00:06:29,620 --> 00:06:37,019
directory and within here the main configuration file is one called main.cf. So really try to

61
00:06:37,019 --> 00:06:43,819
remember this location. Etsy PostFix main.cf. Let's go in and have a look at this file then. So we'll

62
00:06:43,819 --> 00:06:48,620
go in and say main.cf hit Enter. Now within here we're going to see a whole bunch of different

63
00:06:48,620 --> 00:06:54,139
information. We can see how we can configure our SMTP banner which will populate our host

64
00:06:54,139 --> 00:06:59,579
name using a variable value and the mail name. If we scroll on down we see a lot of information

65
00:06:59,579 --> 00:07:05,660
relating to encryption i.e. transport layer security but further down this is really where we

66
00:07:05,660 --> 00:07:11,980
want to be focusing on. So we can specify our host name which is system. In this case here if we

67
00:07:11,980 --> 00:07:17,420
scroll on up this is the value here that's going to be populated my host name. In my case it will

68
00:07:17,420 --> 00:07:24,620
be system. Scroll back down. We can see things such as the aliases. Now aliases are very very

69
00:07:24,620 --> 00:07:31,180
useful. What this means is that we can ultimately alias a particular user so that mail for that

70
00:07:31,180 --> 00:07:37,900
user can be redirected to another user. So a good example of this would be taking an alias or rather

71
00:07:37,900 --> 00:07:46,220
specifying an alias within this particular file that is the Etsy aliases file and we could map

72
00:07:46,300 --> 00:07:53,100
the root user to my local account of IPv0 for example. So if I wanted to check the emails that

73
00:07:53,100 --> 00:07:59,260
were sent to the root user without having to change accounts i.e. without having to log in as the root

74
00:07:59,260 --> 00:08:05,820
user I could actually just have any mail that is sent to the root user relayed to my local account

75
00:08:05,820 --> 00:08:11,660
and still read them. Now my destination here these are all the locations specified here. So what this

76
00:08:11,660 --> 00:08:17,580
means is that if the server happens to get any emails for any of the addresses that you see here

77
00:08:17,580 --> 00:08:23,820
the server is going to keep them and deliver it to the local user. So if I send a message to

78
00:08:23,820 --> 00:08:29,900
at localhost for example it will be for my local user here. Now one thing to note here is that we

79
00:08:29,900 --> 00:08:35,100
have this configuration for relay host this is left blank. I just want to have a word of warning

80
00:08:35,100 --> 00:08:41,340
that you probably and I should say strongly want to leave this as blank. The reason being is that

81
00:08:41,340 --> 00:08:47,580
this could potentially compromise your system and that your server could ultimately be targeted to

82
00:08:47,580 --> 00:08:52,700
really spam messages. So quite honestly if you do not know what you're doing with this I really

83
00:08:52,700 --> 00:08:57,980
really would leave this blank. So now that we know that our main configuration file is this one right

84
00:08:57,980 --> 00:09:05,660
here main.cf and we are aware of our aliases and destinations so on so forth. Let's begin doing some

85
00:09:05,660 --> 00:09:10,620
basic testing of our mail service. So what I'm going to do here is I'm just going to exit out

86
00:09:10,620 --> 00:09:15,820
and I will clear the screen. So let me show you how we can actually use this mail service if I just

87
00:09:15,820 --> 00:09:22,220
see mail and say dash s for the subject matter. So I will just give this the subject matter of

88
00:09:22,220 --> 00:09:28,379
hello world. Now realistically I could send this email out into the big bad world. So I actually

89
00:09:28,379 --> 00:09:35,659
have a little test account called johnredtestatoutlook.com. Now if my local settings were configured

90
00:09:35,659 --> 00:09:42,939
correctly I had a reputable domain name and not just ipv0 at system which looks kind of fishy.

91
00:09:42,939 --> 00:09:48,939
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

92
00:09:48,939 --> 00:09:56,299
this is just some tests that will fail sad face. Now to end the message you might have to press

93
00:09:56,299 --> 00:10:03,500
ctrl d. In my case I actually have to press ctrl shift d and with that the mail will be sent off

94
00:10:03,500 --> 00:10:09,019
but the reality is given that my domain is a little bit dodgy this is going to fail it's going

95
00:10:09,019 --> 00:10:16,139
to be rejected by the outlook servers. If I happen to issue the command mail we can actually see here

96
00:10:16,139 --> 00:10:21,980
this is an undelivered mail returned to sender and a hit enter. Now do not despair like I say if

97
00:10:21,980 --> 00:10:28,139
my domain was configured correctly and I really had an ipv0.com address or whatever it may be

98
00:10:28,139 --> 00:10:33,179
then this configuration would work just fine but for the purposes of our little testing

99
00:10:33,179 --> 00:10:37,899
do not worry about that at all. What we're now going to do is to try to test an email

100
00:10:37,899 --> 00:10:44,539
by sending it to another account on this system. So what I will do is I will say mail dash s and

101
00:10:44,539 --> 00:10:51,339
I'll maybe say hey there admin that will be the subject matter and what I will do is I will target

102
00:10:51,339 --> 00:10:58,620
the root on the local host which is this machine right here. So if I hit enter cc I don't want to

103
00:10:58,620 --> 00:11:06,700
add anyone in and I'll just say hello mr. Root this is John. I will press control shift D. Now if I

104
00:11:06,700 --> 00:11:14,700
happen to hit the mail command here notice there is no mail for ipv0 that is because ipv0 was the

105
00:11:14,700 --> 00:11:19,899
sender of this mail and the recipient should be the root account. So what I'm going to do is I'm

106
00:11:19,899 --> 00:11:27,100
going to change into my super user which is now the root account. If I hit the mail command now

107
00:11:27,580 --> 00:11:32,860
see we actually do have a message for the root account and we can see the subject here is hey

108
00:11:32,860 --> 00:11:40,940
there admin we can see the sender was ipv0 if I hit enter we can actually see the contents of that

109
00:11:40,940 --> 00:11:47,019
message. Now if I wanted to hit enter again we can see there's no more messages and now if I just

110
00:11:47,019 --> 00:11:53,980
change back to ipv0 once again what I'm now going to do is I'm going to modify my aliases file remember

111
00:11:53,980 --> 00:11:59,100
we talked about that so I'll go into the etse directory and then aliases again remember this

112
00:11:59,100 --> 00:12:04,220
location very very important we can actually see here there already is an aliase configured meaning

113
00:12:04,220 --> 00:12:11,820
that if we happen to send a message to quote unquote postmaster it's actually going to be sent to

114
00:12:11,820 --> 00:12:19,340
the root account. To check this out if I just go back out here and I say mail s hey postmaster

115
00:12:19,340 --> 00:12:27,340
and I address it to the postmaster of localhost I'll just say hey p.m for postmaster control

116
00:12:27,340 --> 00:12:35,500
shift d if I say mail again no mail for ipv0 but if I go into my super user and I say mail now

117
00:12:36,060 --> 00:12:43,420
notice here we're in the root accounts for here and we have received the message that was directed

118
00:12:43,419 --> 00:12:49,979
to postmaster so postmaster has been relayed to the root account instead. Now check this out if I

119
00:12:49,979 --> 00:12:57,179
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

120
00:12:57,179 --> 00:13:03,500
will say sudo nano I'll go into the etse aliases once again and I'm going to add another piece of

121
00:13:03,500 --> 00:13:09,740
information I'm going to see the root account should go to ipv0 now think about this we actually have

122
00:13:09,740 --> 00:13:18,139
a chain going on right here if someone sends a message to postmaster it's going to be targeted

123
00:13:18,139 --> 00:13:26,379
for root however because it's now targeted for root root is now mapping to ipv0 so ultimately

124
00:13:26,379 --> 00:13:33,899
whenever someone sends a message to postmaster it's really going to go to ipv0 which is my local

125
00:13:33,899 --> 00:13:40,299
account check this out then okay very very important now that we have modified this aliases

126
00:13:40,299 --> 00:13:47,259
file it will not take effect just yet what I've got to do is issue this command sudo new aliases

127
00:13:47,259 --> 00:13:52,539
now this is very very important we have to understand that the etse aliases file will not

128
00:13:52,539 --> 00:13:58,860
be updated it will not take effect until this particular command is issued so if I hit enter now

129
00:13:58,860 --> 00:14:05,740
check this out like I say in our aliases we send to postmaster postmaster goes to root root goes to

130
00:14:05,740 --> 00:14:13,659
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

131
00:14:13,659 --> 00:14:21,419
this to postmaster at localhost and the message will just be just letting you know I love donuts

132
00:14:21,419 --> 00:14:25,899
not sure why the postmaster would have to know this information but nevertheless let's go with it

133
00:14:25,899 --> 00:14:32,539
ctrl shift d now who do you think is going to get this message then let's first try the super

134
00:14:32,539 --> 00:14:37,659
user so we are now the root account let's see if the root account has this message the I love

135
00:14:37,659 --> 00:14:45,259
donuts message is not there so if I press q to quit spot I change into ipv0 or rather that should be

136
00:14:45,259 --> 00:14:53,259
substitute user ipv0 so I'm now ipv0 clear the screen I now say mail check this out it's only ipv0

137
00:14:53,259 --> 00:14:58,620
who got that message and I can hit enter and we can actually see the contents of the email right

138
00:14:58,620 --> 00:15:05,259
here so notice it was originally sent to postmaster which would have been relayed to the root but it

139
00:15:05,259 --> 00:15:11,419
didn't actually go into the root account the root account automatically just passed it on via the alias

140
00:15:11,419 --> 00:15:17,580
to ipv0 so really that is us for our basic introduction into using postfix so really we

141
00:15:17,580 --> 00:15:24,220
want to be remembering that it's a postfix main dot cf configuration file we also want to remember

142
00:15:24,220 --> 00:15:30,780
that we can create aliases in the etsy aliases file and if we want those changes to actually take

143
00:15:30,780 --> 00:15:37,900
place we must use the new aliases command but for now as we can see here we are reading our files

144
00:15:37,900 --> 00:15:44,140
we want to see a better way how we can actually manage our local mail service and well that's

145
00:15:44,139 --> 00:15:48,059
what we're talking about in the very next nugget so I hope this has been informative for you and

146
00:15:48,059 --> 00:15:52,860
I'd like to thank you for viewing

