1 00:00:00,000 --> 00:00:01,890 [No audio] 2 00:00:01,890 --> 00:00:05,850 Sendmail. Sendmail is another one of 3 00:00:05,850 --> 00:00:09,120 the major service that is used in Linux 4 00:00:09,120 --> 00:00:12,420 or Unix environment. Sendmail is a 5 00:00:12,420 --> 00:00:15,360 program that is run in your Linux 6 00:00:15,360 --> 00:00:18,210 systems to send emails and receive 7 00:00:18,210 --> 00:00:21,630 emails. But I would say primarily it is 8 00:00:21,630 --> 00:00:24,540 used to send emails. Because when you 9 00:00:24,540 --> 00:00:27,270 have a program running in your system or 10 00:00:28,020 --> 00:00:30,060 or a workflow running in your system, 11 00:00:30,360 --> 00:00:33,450 and you do wanted to be notified if this 12 00:00:33,479 --> 00:00:36,000 if the process finished, or if the whole 13 00:00:36,000 --> 00:00:38,940 workflow finished successfully, you do 14 00:00:38,940 --> 00:00:41,490 want to get an email at the end. That's 15 00:00:41,490 --> 00:00:43,980 when you actually have to have some kind 16 00:00:43,980 --> 00:00:46,590 of mailing program. And the most and 17 00:00:46,590 --> 00:00:50,010 readily used program that runs in 18 00:00:50,010 --> 00:00:53,310 Linux is sendmail. So the purpose is, 19 00:00:53,520 --> 00:00:55,620 again to send and receive emails, the 20 00:00:55,620 --> 00:00:58,800 files that the configuration files of 21 00:00:58,800 --> 00:01:01,980 sendmail is /etc/mails/sendmail.mc, 22 00:01:02,220 --> 00:01:05,519 which is the main file. mc stands for 23 00:01:05,519 --> 00:01:09,240 mail configuration. And you configure 24 00:01:09,240 --> 00:01:11,850 everything in this and once you actually 25 00:01:11,850 --> 00:01:15,180 compile this configuration file, it 26 00:01:15,180 --> 00:01:19,205 sends all its configuration to /etc/mails/sendmail.cf, 27 00:01:19,205 --> 00:01:25,140 Many people go straight to sendmail.cf, which is also 28 00:01:25,140 --> 00:01:27,360 okay, it's fine. It's nothing that 29 00:01:27,360 --> 00:01:29,250 you're going to break anything. But it 30 00:01:29,250 --> 00:01:32,460 is a standard and practical 31 00:01:32,460 --> 00:01:35,850 way that you should always go to sendmail.mc, 32 00:01:35,850 --> 00:01:38,460 and then compile it, start the 33 00:01:38,460 --> 00:01:40,710 system, start that sendmail, and it 34 00:01:40,710 --> 00:01:42,540 automatically push the changes out to 35 00:01:42,540 --> 00:01:45,660 the configuration file. All the 36 00:01:45,660 --> 00:01:47,910 configuration file of sendmail is 37 00:01:48,060 --> 00:01:51,613 located, all the files are located in et 38 00:01:51,613 --> 00:01:55,770 /etc/mail directory. The service that you 39 00:01:55,770 --> 00:01:59,610 need to run or start with your system 40 00:01:59,640 --> 00:02:02,790 start and stop program is systemctl 41 00:02:02,790 --> 00:02:06,150 restart sendmail. Sendmail is one of 42 00:02:06,150 --> 00:02:08,400 those programs that does not have d at 43 00:02:08,400 --> 00:02:11,910 the end. But it does not mean that it's 44 00:02:11,910 --> 00:02:14,790 not running at all times. It does run in 45 00:02:14,790 --> 00:02:17,070 the background, it is still a daemon, but 46 00:02:17,070 --> 00:02:19,740 it's somehow never got a d at the end. 47 00:02:21,060 --> 00:02:23,460 The command that you will run if you 48 00:02:23,460 --> 00:02:26,310 want to send email out from your server 49 00:02:26,460 --> 00:02:30,090 would be mail -s which is an 50 00:02:30,120 --> 00:02:33,000 option, and then quotes, you'll put a 51 00:02:33,000 --> 00:02:35,190 subject line followed by the email 52 00:02:35,190 --> 00:02:37,560 address that you are sending it to. Once 53 00:02:37,560 --> 00:02:40,320 you send it and hit return on your 54 00:02:40,320 --> 00:02:42,330 keyboard, it will bring you a kind of 55 00:02:42,360 --> 00:02:47,430 interactive or like vi kind of mode 56 00:02:47,430 --> 00:02:49,770 where you will type everything. And then 57 00:02:49,770 --> 00:02:51,120 once you're done, then you will just 58 00:02:51,120 --> 00:02:54,660 simply do Ctrl D, and it will get you 59 00:02:54,660 --> 00:02:57,420 out of that mail program, and it will 60 00:02:57,420 --> 00:03:00,960 send the email out. So to illustrate 61 00:03:00,960 --> 00:03:03,660 that more, we will we'll get into our 62 00:03:03,660 --> 00:03:06,000 Linux machine. And we will look at some 63 00:03:06,000 --> 00:03:08,490 of the files and commands are related to 64 00:03:08,490 --> 00:03:11,700 sendmail. So we have our server here, 65 00:03:11,700 --> 00:03:15,540 we'll log in as ourself, and most likely 66 00:03:15,570 --> 00:03:18,990 it has already logged in as root. How do 67 00:03:18,990 --> 00:03:21,240 we verify it, we'll just run whoami, 68 00:03:21,270 --> 00:03:23,670 which is a command that tells you which 69 00:03:23,670 --> 00:03:26,520 user is logged in. I'm gonna move the 70 00:03:26,520 --> 00:03:28,650 window to the side. So we'll see exactly 71 00:03:28,650 --> 00:03:30,960 what we're doing based on our slide in 72 00:03:30,960 --> 00:03:33,840 the back. So the first configuration 73 00:03:33,840 --> 00:03:37,290 file is sendmail. But of course, before 74 00:03:37,290 --> 00:03:39,030 we get into the files, the first thing 75 00:03:39,030 --> 00:03:41,850 we need to do, is we need to find out 76 00:03:41,850 --> 00:03:44,880 whether we have the sendmail program 77 00:03:44,910 --> 00:03:48,780 installed in our system. And how do we 78 00:03:48,780 --> 00:03:51,300 need to find that out? There is a command 79 00:03:51,300 --> 00:03:54,960 that you run rpm -qa, and then 80 00:03:54,960 --> 00:03:58,320 you grep for sendmail. rpm -qa 81 00:03:58,320 --> 00:04:01,980 list every single program or repository 82 00:04:01,980 --> 00:04:05,070 or package that you have installed in 83 00:04:05,070 --> 00:04:08,100 your system. So I ran it I see it it's 84 00:04:08,100 --> 00:04:10,290 not there. So the next thing we'll do is 85 00:04:10,290 --> 00:04:13,380 we will install it to install a package 86 00:04:13,380 --> 00:04:18,480 you will run yum install sendmail. 87 00:04:19,440 --> 00:04:21,810 And of course remember that this is 88 00:04:21,810 --> 00:04:24,360 going to go outside on the internet 89 00:04:24,480 --> 00:04:27,149 where all the CentOS repositories are 90 00:04:27,149 --> 00:04:29,130 located and it will get that package 91 00:04:29,130 --> 00:04:31,350 from there. If you do not have internet 92 00:04:31,350 --> 00:04:33,750 access on your Linux machine, it's not 93 00:04:33,750 --> 00:04:35,580 going to work it will fail, it will say, Cannot 94 00:04:35,580 --> 00:04:37,380 reach the internet or cannot reach the 95 00:04:37,650 --> 00:04:42,300 repositories mirrors. So once I run yum 96 00:04:42,330 --> 00:04:44,940 install sendmail, it's telling me that 97 00:04:44,970 --> 00:04:47,670 it found one package and the size, do you 98 00:04:47,670 --> 00:04:49,410 want to install it? Yes, of course I do 99 00:04:49,410 --> 00:04:51,570 want to install it. I'll click Yes. And it 100 00:04:51,570 --> 00:04:54,210 will start installing it, download, 101 00:04:54,210 --> 00:04:57,270 install, verify, cleanup, all that stuff is going to go through. 102 00:04:57,270 --> 00:05:05,040 [No audio] 103 00:05:05,040 --> 00:05:07,470 Okay, the installation of sendmail is 104 00:05:07,470 --> 00:05:10,320 completed. Anyway, there is an another 105 00:05:10,320 --> 00:05:12,330 package that you do need to install, 106 00:05:12,510 --> 00:05:14,130 which does the configuration of your 107 00:05:14,130 --> 00:05:17,937 sendmail. And that is sendmail-cf. 108 00:05:17,937 --> 00:05:22,625 [No audio] 109 00:05:22,625 --> 00:05:24,127 Click yes to install it. 110 00:05:24,127 --> 00:05:30,234 [No audio] 111 00:05:30,234 --> 00:05:31,380 Okay, it is 112 00:05:31,380 --> 00:05:33,900 complete, it's awesome. So once you have 113 00:05:33,930 --> 00:05:36,120 the package installed, it means it 114 00:05:36,120 --> 00:05:39,030 already creates your directories for you 115 00:05:39,030 --> 00:05:41,520 where they belong, it already creates a 116 00:05:41,520 --> 00:05:44,040 configuration file for you. So the first 117 00:05:44,040 --> 00:05:45,150 thing we have to do is go to 118 00:05:45,150 --> 00:05:48,120 configuration file to define its 119 00:05:48,120 --> 00:05:51,990 configuration parameters. The 120 00:05:52,200 --> 00:05:54,450 configuration files, all of them are 121 00:05:54,450 --> 00:05:58,860 located in /etc/mail, and you will see 122 00:05:58,860 --> 00:06:02,760 right here, the first third one from the 123 00:06:02,760 --> 00:06:06,660 top, it says sendmail.mc. This is where 124 00:06:06,660 --> 00:06:09,360 we will define our mail relay server. 125 00:06:09,480 --> 00:06:12,090 And what is a mail relay server. Mail 126 00:06:12,090 --> 00:06:14,520 relay server is a server that is set up 127 00:06:14,520 --> 00:06:16,680 in a company and environment which will 128 00:06:16,710 --> 00:06:19,110 accept your emails that are coming from 129 00:06:19,110 --> 00:06:21,510 any of the server and then deliver. It's 130 00:06:21,510 --> 00:06:24,720 like a middleman which takes, on the left 131 00:06:24,720 --> 00:06:26,460 hand it takes your message, on the right 132 00:06:26,460 --> 00:06:28,860 hand it delivers it. It's a server as 133 00:06:28,860 --> 00:06:30,870 well. Sometimes it's a Windows Server, 134 00:06:30,870 --> 00:06:32,520 sometimes it's Linux server depending on 135 00:06:32,520 --> 00:06:34,260 your environment, but it's a mail relay 136 00:06:34,260 --> 00:06:40,230 server. Okay, so when we come down to 137 00:06:40,230 --> 00:06:42,510 this file, anything that starts with 138 00:06:42,510 --> 00:06:44,970 dnl, it means that it's just a comment, 139 00:06:44,970 --> 00:06:46,830 you can ignore that, we have to come 140 00:06:46,830 --> 00:06:49,980 down to a line where it says define some 141 00:06:49,980 --> 00:06:53,880 SMART_HOST. And the SMART_HOST is our 142 00:06:53,880 --> 00:06:56,970 SMTP server or relay server where we are 143 00:06:56,970 --> 00:06:59,400 going to send our emails and it's going 144 00:06:59,400 --> 00:07:01,800 to accept it. So you just put the host 145 00:07:01,800 --> 00:07:04,590 name with a fully qualified domain name, 146 00:07:04,740 --> 00:07:06,840 meaning the host name dot your domain 147 00:07:06,840 --> 00:07:10,200 name.com, you will add it here. Once that 148 00:07:10,200 --> 00:07:15,600 is added, and next thing you have to do 149 00:07:15,660 --> 00:07:18,162 is you have to start the service. 150 00:07:18,813 --> 00:07:24,480 systemctl restart or start sendmail. 151 00:07:24,480 --> 00:07:30,450 [No audio] 152 00:07:30,450 --> 00:07:32,160 Okay, the sendmail service has 153 00:07:32,160 --> 00:07:37,800 restarted. Let's check the status. It 154 00:07:37,800 --> 00:07:42,120 says it's up and running. You can also 155 00:07:42,120 --> 00:07:44,010 check the status of sendmail by running 156 00:07:44,010 --> 00:07:46,980 the command ps -ef. And then you 157 00:07:46,980 --> 00:07:49,470 could just simply grep for sendmail. And 158 00:07:49,470 --> 00:07:51,960 here it will tell you the second one, 159 00:07:51,960 --> 00:07:53,700 the first one is just telling you the it 160 00:07:53,700 --> 00:07:57,030 is accepting connections. And this is 161 00:07:57,030 --> 00:07:59,430 the main process that runs it. You will 162 00:07:59,430 --> 00:08:01,830 kill it by typing the command kill 163 00:08:01,860 --> 00:08:06,180 followed by the process ID, 6023. Now you 164 00:08:06,180 --> 00:08:10,530 could send emails and the command to 165 00:08:10,530 --> 00:08:15,570 send email is mail -s subject line 166 00:08:15,570 --> 00:08:23,010 is mail setup. And I want to send it to 167 00:08:23,010 --> 00:08:27,090 myself. So I'll put my email which is 168 00:08:27,120 --> 00:08:32,190 imran_ny@hotmail.com. I hit enter. And 169 00:08:32,190 --> 00:08:34,620 once I hit enter and that's where the 170 00:08:34,620 --> 00:08:37,140 mail body is. Whatever that you want to 171 00:08:37,140 --> 00:08:40,440 type the text goes in. hi hellow 172 00:08:41,580 --> 00:08:45,120 goodbye. And once it's done, all you 173 00:08:45,120 --> 00:08:49,020 have to do is type Ctrl D, Ctrl D is 174 00:08:49,020 --> 00:08:51,539 typed, you will get out of your mail 175 00:08:51,539 --> 00:08:54,539 program, and that's how you send and 176 00:08:54,570 --> 00:08:58,140 configure your mail. Mail again, once 177 00:08:58,140 --> 00:09:01,890 again, it's one of the critical services 178 00:09:01,890 --> 00:09:03,930 that oftentimes you do have to configure 179 00:09:03,930 --> 00:09:07,530 in your system. So familiarize yourself 180 00:09:07,800 --> 00:09:11,250 with the mail files, the configuration, 181 00:09:11,250 --> 00:09:13,260 the how to start and stop this mail 182 00:09:13,260 --> 00:09:16,546 service, and how to monitor it and how to send mails 183 00:09:16,546 --> 00:09:18,293 [No audio]