 All right, it's time a lot of you have been waiting for a video on how to set up an email server So that's what we're gonna do in this video So it is that setting up an email server is actually a notoriously difficult process But last year I'm very glad I did this last year when I set up my own email server. It was very painful But once I finally figured it out. I actually sort of left a rope for myself in that I wrote a Script that did most of the work for you and installs the dependencies and configures them all together So I'm gonna be using that in this and you can of course as well It's on my github, but I also want to explain the logic of an email server and some stuff about it. Okay, so What a email server usually consists in is a post fix server Which sends mail a dove caught server which receives mail you have to configure them together You got to make sure they're they're locking into with each other You'll usually want spam assassin to keep you know get spam away and we'll be installing that as well and one of the biggest questions I get when Talking about email server or like let's say you have your own domain a lot of people have the idea that oh if I just Have some random domain. I might send mails to Google or something like Gmail and They might get blocked. So we're also gonna set up open DK. I am which allows it basically validates your domain and your email as legitimate And it's a way to you know, so spam filters won't get you and stuff like that now in order to do all this You are gonna need some kind of VPS the script that I have made works on Debian and Ubuntu. I have tried it on both I well, I've tried it on vulture VPS is So I know some of you guys are using it because I did so it might work on If you have another VPS provider linode or digital ocean, but I know they work for vulture We are gonna be Creating a SSL certificate that is we want encrypted connection duh to our server So we'll be setting that up now the first thing we want to do though is we want to actually set up some DNS records Okay, so go to your registrar or wherever you set, you know, if you have a DNS server you can open that But we're gonna want to add some DNS records so here again my website unibomber.com looking at the DNS records the big one is You want to go make an MX record and now a MX record is basically just the record We did not mean to do that It's the record that basically tells whoever's trying to email your domain where to look, you know, where to actually send your mail So we're gonna add an MX record And my face is like how to say that sort of annoys me. I don't know it's been doing that a lot today Not quite sure why? so we are gonna add an MX record and basically it doesn't just host leave it blank you can put mail and Then your site after it and you want at the very end a trailing dot that is if you're using epic I think I think other other registrars don't necessarily require that but So if you go to you also want to set up so we're gonna send all our email server Basically is going to be at mail dot whatever, you know your website So we're telling it to go there and additionally we're gonna want to set up that sub domain as well so you want to make a C name record for that and this is more actually to figure out this is more to make Cert bot work, but we're gonna go ahead and make that we're gonna make a C name domain for Mail and we're gonna direct that to unibomber.com with a trailing period once again and for good measure I'm just gonna put in WWW mail. I always do that. I always double up Putting in WWWs for my subdomains. Oh, I gotta remember that trailing period So once you have that you can save that and you're done with your DNS records for now We'll actually come back here at the very end. We're gonna add some text records that have to do with DK I am so you can validate your emails and stuff like that. Alright, so once you have that I'm gonna go over here Actually, maybe I'll bring my face because you know, I always I feel lonely if I'm on a workspace alone. I am going to Log into my website. Okay, so now I'm here Now the script that I made You can get it at this Link right here. Okay, you can download it from my website Luke Smith dot XYZ slash email whiz dot sh So let's do that. Okay so Luke Smith dot XYZ email whiz Okay, so now we're gonna download that but before we even run that there's one more thing we want to do We want to actually configure that subdomain so that it can take encrypted connections So, you know, we we want to use cert bot to give it HTTPS and stuff like that. So let's do that first So how we want to do that? We want to create a dummy domain in a subdomain in engine X So if you remember from the videos before Engine X which is our web server It keeps its available sites in Etsy slash engine X slash sites available Okay, I feel like my webcam is like off sync just so much today. I don't know. Maybe I'm just imagining it But anyway, so in this folder, I've actually already created a file called mail so I'm gonna open this up and This is you just want to create a file that looks like this. You can name it mail. You can name it whatever So long as it has this kind of information You want to listen on port 80 if you have IPv6 you want to have this line as well You can give it just some random root directory. It doesn't actually matter where I'm just gonna give it mail. We're not actually gonna set up like a website at this location It's just gonna be a dummy website to get you know our Certificate and but the important thing is your server name should be mail dot whatever dot com and WWW mail, okay? Now once you have that you can activate that site by taking that file and linking it I'm gonna link it make a symbolic link from there to sites Enabled, okay, once that happens engine X will treat that as a real site and we will tell We will reload engine X. Okay, so once you do that we can go ahead and get Get SSL for that get encryption We'll run that and it will ask what domains you want to do. I'm gonna pick mail and WWW mail That'll take a second Not too long and it'll ask do you want to redirect say yes if you haven't run it before of course It'll ask you for your email and stuff and other things, but all right, so that should be done. Okay, so now let's test that Always leave in my face behind We should be able to go to mail Uniboomer.com and you should get this yes, we got an error, but this is the correct error You want to have like engine X error? So just to be clear if you typed in some random Letters and then typed a subdomain it would have this but what we want to see is this okay, and notice also up here It says connection is secure that means it worked So great. We're basically halfway there. All right, so the other half is more or less running the script that I made Okay, so this script is going to install postfix and Dovcott and configure them together It's gonna install spam assassin everything else. Let me just go ahead and start it It will start by downloading some of these programs and it's gonna ask you Oh, yeah, this I think I already down downloaded them. I just haven't installed them So it's gonna bring up a menu like this say internet site And then it's gonna ask you you for your system mail name. Just put in your domain name Uniboomer.x.com Don't put in mail before it just put in you know the clean domain and so that should take a little bit of time I'll probably stop this because it might take a little bit, but what this is gonna do It's gonna be installing you can see what it's doing It's installing postfix and Dovcott and all the other things it that are required and actually in this script Maybe we can look at the script in the meantime Email whiz yeah Yeah in this script There's just a bunch of configuration that goes on that I make it do manually It sets up like what your your mailboxes are gonna look like you know what their name drafts junk inbox sent trash Archive archive. I didn't even know I added that but and then all this complex stuff It was such a pain figuring out all the stuff and configuring them with spam assassin But how it's gonna work once this is done is you whenever you create a user actually we can go ahead and do this We can go ahead and do this actually So I'm gonna log in To my server, so now I'm gonna have two instances into my server It's apparently taking a while. I'll just okay So one thing how you set up email accounts or I mean we can go ahead and start doing this Oh, you want to add users? Let's say I want to be named Ted. Okay? I want the mail account Ted at uniboomer.com Okay, what you can go ahead and do is say user add and Then you can say you want to say M. That means automatically create create this user's home directory You want to do capital G and that means this is a group that this person's gonna be added to and add mail Basically that means whenever you add a user to the mail group that means that they are going to be able to You know receive mail send mail stuff like that and Ted is the thing we're going to the name We're gonna give actually I'm gonna get make the shell for this guy Bend off bash. I think it's s for changing the shell. All right, that should work Okay, so we went ahead and made him and you'll also definitely want to give him a password In fact, you need a password in order to be in order to log on we will deal with that in a second So I'm just gonna make up a little password for him Okay, now. Okay, great. Perfect. That's perfect timing because now it looks like our script is done It's installed all the stuff we need but there's still stuff we need to do. Okay, that's why there's this big now thing Okay, so there are three text records that we have to add to our little text record tab over here on our DNS records So to be clear, these are also saved In my script, I think I saved them to like DNS. Yeah, they're saved to this file if you lose track of them So basically these are the like DKIM this first one is DKIM to validate your email Or yeah to validate your domain and stuff like that. So let's go ahead and add this So you if you put it in manually, I think you have to include like the entire domain I think I can get away with just including the sub domain if I Let's see add record the host is gonna be that sub domain And then the text entry is gonna be everything from V to the end of the line. This first one's gonna be really really long But yeah, you can just put that in there Then we're gonna add two other ones. So we're gonna add one for a D mark So these two are basically gonna be I don't know if you know this, but it's actually really easy to Spoof emails. So these two things are to avoid, you know, basically to prevent that from happening on your server So I'm gonna add that in and I'm gonna add this last one in Copy this and hopefully this will all work if it doesn't I will fix it live and you will know what is happening Okay, so I'm gonna save those Saving them Okay, come on In the meantime, I have actually Taken the unusual step of okay should be saved I've taken the unusual step of installing Thunderbird because now Thunderbird or any other mail application We can now use to install, you know, basically log into our server. Okay? Now, of course, I usually use mutt, but we'll use Thunderbird because it's more, you know, normie friend Okay, so let's do this. So we will just set up an email account and I'm gonna say my name is Ted. My email address is Ted at unibomber.com my password. I'm gonna put in my password Okay, so it's gonna take a little bit of time Thunderbird I think has some abilities to automatically guess what your mail information is. I'll go ahead and say that I actually chose very normal things for Basically, if you're using a program that requires you to put in like server information This is gonna be your server information Your SMTP port again, that's for sending mail. That's gonna be mail dot whatever your domain is and the port is gonna be 587 That's typical. The IMAP server is gonna be the same thing And the port is gonna be 993 and your username This is actually important because you might get confused by this your username is gonna be just the beginning It's just gonna be, you know, Luke instead of Luke at Luke Smith dot XYZ, right? Okay, so let's see. I think that work. We'll see if that works. I don't actually know how Thunderbird Start TLS. No, I don't think it should be start TLS. I feel like that. Well, anyway, we'll see if it works It's not going to. All right. Well, we'll do manual. It would have made a connection by now Okay, this should be oh, yeah, this is done. All right, as I said IMAP should be 993 And this should be SSL wait, is it whatever? Yeah, 580 587 okay SSL Okay, maybe maybe I'm dumb I'm just gonna do put five every set 587. I don't know about that retest Okay, we'll just Run with that. Let's see if that works. Okay, so I have an inbox. It seems to have logged in Oh, and it's detecting all my mailboxes. So that means there's stuff here So I'm going to log on to my other email address and I'm gonna send email to the server to make sure it works Okay, let's do that Okay, so here is a test email Okay, so again, we're sending to Ted at uniboomer.com test email Let's see if that works It's gonna send Hopefully and it's gonna appear here in just a second. Let's see is there a Refresh button. Oh, look at that. Look at that. That's beautiful. So here's our mail. We can now receive mail now The big test is can we? Can we like send mail to other places and let's say Gmail? Okay, Gmail is usually the hard one because they you know, they they're very picky about DNS settings and stuff like that So let's test this out. So I'm gonna send it to this Gmail account that I have I'm gonna say Let's see if Open DK I am works. It's gonna be the title of our email. Let's see if this works Best Luke no, we'll do Ted. Okay, so I will send that now usually if you If the mail is undeliverable a lot of times you'll get an email back or something like that not all the time So I am gonna log. I'm gonna I guess I'll Let's see. I'll just pull up a private browsing window and go in here log on to Gmail First time I've used Gmail in a while Up and here it is so we have our email got it from I don't know the source we wanted let's see It's standard encryption looks all everything looks good. There's one additional test we can have or if you're having any problems This is one of the things you can do. There are a couple sites out there I'm gonna take my face There are a couple sites out there like this one that will actually test your DK I am settings or your SPF settings We technically put in a record for that as well. So what you can do is they will give you a dummy email address I'm gonna copy this email address and We can send if we want to test we can just send any old email to here. Okay, I'll just put whatever and We'll send that and they will tell you if there's anything wrong with your settings or something like that So here we have the raw email right here. It's it's encrypted and all this stuff That's as expected and it says it passes SPF passes DK. I am something's going on with D mark Maybe it's still load. Oh, yeah, it's still loading. Let's hope it passes Again like these settings are for you know making sure you don't like people don't spam or not spam Like spoof emails. It's actually really easy like you could just go and mutt and just change your from address and pretend You're emailing from someone authoritative and of course SPF and D mark are to prevent that I don't know why this is taking so long. I actually in the break. I tried it already and it was working Okay, maybe I'll maybe we'll wait on that for a second In the meantime, so as I said if you want to add if you want to add a new mail user You can always use user add you want to use him to add a new directory for them G capital G. I should say adds them to the mail group and You'll probably want to create a shell for them, you know been bash and Just name them whatever so let's name someone Billy Okay, and you'll definitely want to make a password for them as well If you already have a user that you want to add to the mail group because not all user Not all users will automatically have the ability to send and receive mail. You can say user mod a a not M capital G Mail and then say whatever the name is so let's say, you know Billy already exists and we want to add them to the mail group We just run user mod and you know that'll do it so that should work with that. Is this gonna ever work? I don't know anyway So that should be about it If you have a try it out for yourself if anything goes wrong There you can open up an issue on the github and stuff like that But in general I've been you know the the email that I'm using right now is run Like I just installed it like last week. I had to reinstall my server. So this script works I know a bunch of other people who have used it that it works If anything goes wrong though, be sure to evaluate what's going on look at the source code and stuff like that and to be clear the Configuration files. I mean this goes for pretty much any program on Linux But if you want to look at system configuration go to Etsy and let's say you want to look at spam assassin Okay, you want to see what kind of rules you can make in spam assassin? You can look up how to add new rules here. You can learn how to whitelist or blacklist particular things That's a good place to do it. I I think I forget where exactly I add Like I have a script offline that adds if I want to block an address it logs into my server and adds a line to spam assassin or something like that Or the same thing if you want to change postfix again, that's for sending mail If you want to change some custom settings, you can go into their main configuration and change some things But in general like a lot of the again my script sort of makes everything fit together So just bear that in mind if you change something it might affect other things But yeah, so that's basically it. That's how you use it and let's see where I'll check into what why this is not loading Okay, it's probably nothing though Okay. Yeah, this is just verification the dmark thing did work. I just sent another email I think it was just a one-time glitch or something. I didn't change any other settings So yeah, that that should be fine. All right. Yeah, that's it