kenetik Posted June 7, 2013 Share Posted June 7, 2013 Free Perfect Email Server - Detailed Tutorial This tutorial covers all the details steps for creating your own custom email server using a Virtual Private Server running Ubuntu 12.10 x64 with iRedMail 0.8.4, iRedAdmin, PostgreSQL, Roundcubemail, Awstats, Apache and SSL Certificates. I used Digital Ocean SSD VPS for this tutorial. (Included in this tutorial is a coupon for 2 months of free service.) If you already have a perfectly configured server, you can skip to: 'Install iRedMail'. README.md on GitHub | HTML Formatted Version Create a Droplet (aka VPS) I highly recommend using Digital Ocean SSD VPS for this setup. If you are creating a new account, use the coupon SSDPOWER for 2 months of free service. After creating a new account, click Create Droplet * Screen Shot of Creating a Droplet via Digial Ocean Assign hostname (for this tutorial I will be using mail.yourdomain.com) From my tests 2GB/2CPUS/40GBSSD configuration works the best, but for trial and error we will use the smallest configuration. Screen Shot of Assigning Hostname Select Region - This is based on your location, or potenial users location. I chose San FranciscoSelect Image - We will be using Ubuntu 12.10 x64 for this tutorial. Screen Shot of Selecting Image and Location [*]Click Create Droplet - You will be greeted with a message about your droplet being created. (Wait approximately 60 seconds, usual much less.) You will be automatically redirected to your droplet upon it's creation. Check your email for the root password. Screen Shot of Create Button Screenshot of Droplet After Creation [*]Change your server's password Login to your server using a SSH Client (PuTTY/Terminal/Digital Ocean's Console Access) with the details given from the email. In your SSH Client type the following command: ssh root@yourip [*]You will be prompted about a RSA key fingerprint. Type 'yes' as the prompt. yes Screenshot of RSA PromptEnter the random password generated during droplet creation. You should now be logged into your server and see something similar to this: [*]Screenshot of Successful Server Login [*]It is very important to now change the password to something secure of your choice. At the command prompt type the following command: passwd Screenshot of Password Change [*]Reboot your server by typing the following command: Now your in! Let's start configuring! Setup 2GB of Swap Memory This helps with server stability and is optional but highly recommended. Login back into your server and type the following command: dd if=/dev/zero of=/swap bs=1024 count=2097152mkswap /swap && chown root. /swap && chmod 0600 /swap && swapon /swapecho /swap swap swap defaults >> /etc/fstabecho vm.swappiness = >> /etc/sysctl.conf && sysctl -p Screen Shot of Command [*]Check to make sure your swap file is active by typing the following command: free -m will show Swap: 2047 Screen Shot of Swap: 2047 Displayed Swap (virtual ram) is setup! Set your domain's DNS via Digital Ocean's Control Panel Please ensure that your domain's dns are forwarding to your server if you are not using Digital Ocean Add a domain to your account by visiting Digital Ocean's Domain Control Panel | Screen Shot of DCP Click the [Add Domain] button Input your domain, droplet's ip address, and select your droplet. Screen Shot of Domain Inout [*]Click the [Create Domain] button. You should see 'Domain was successfully created'. [*]Click the [Add Record] button Select MX as the Record Type In Hostname input: mail.yourdomain.com. Ensure the trailing . after your domain. [*]In Priority [*]You also want to add a CNAME record for 'mail', '@'. This may seem a little redundant, but it ensures SSL Certification ease later. 10 [*]Click the [CREATE] button Screen Shot of Domain Information Input DNS is set! Ensure VPS is Updated Again, if this is a pre-configured VPS and you now everything is good to go, you may skip this step, but is still recommended From your SSH Client use the following command: apt-get update Screen Shot of Update Results and then this command [*]apt-get upgrade Depending on how many items need to be updated, you will see something similar to the following screenshot and be prompted to continue. Type Y, and your server will begin updating. Screen Shot of Update Process Your up to date! Set your Fully Qualified Domain Name (FQDN) If its already set, it would be a good idea to confirm it Edit the hosts file by typing the following command: nano /etc/hosts Screen Shot of the Hosts file via Nano [*]Change the default line to: 127.0.0.1 mail.yourdomain.com mail localhost You can verify this by rebooting, and typing: hostname -f Your FDQN is now set! Install iRedMail This is the magic software and step for all users From the command prompt type the following command: cd /tmp wget https://bitbucket.org/zhb/iredmail/downloads/iRedMail-0.8.4.tar.bz2 tar jxvf iRedMail-0.8.4.tar.bz2 rm iRedMail-0.8.4.tar.bz2 mv iRedMail-0.8.4 iRedMail cd iRedMail bash iRedMail.sh Your server will begin installing requirements. [*]Once you see the screen 'Welcome and thank you for your use': Select: 'Yes' Screen Shot of iRedMail Welcome Screen [*]/var/vmail is the default storage path, and what I use [*]Select: 'Next' Screen Shot of Default Storage Path [*]Select PostgreSQL with your arrow keys and the spacebar, then 'Next' Sceen Shot of Selecting Database Manager(PostgreSQL) [*]Enter a password for your PostgreSQL admin (you'll need this later) password, then 'Next' Screen Shot of Password Choice [*]Enter your first virtual domain name, yourdomain.com, then 'Next' Screen Shot of Virtual Domain Name [*]Enter a password for your administrator account (you'll need this later, and will eventually will need to change it) password, then 'Next' Screen Shot of Admin Password [*]Select optional components: Fail2ban, and phpPGAdmin are optional, I am chosing to install phpPgAdmin and not Fail2Ban, the rest are required for this tutorial, then 'Next' Screen Shot of Optional Component [*]The selected configurations are complete. Take note, we'll need to move /tmp/iRedMail/config later [*]Type Y to continue Screen Shot of Configuration Completion [*]iRedMail will begin downloading and installing required files. (Approximately ~2 minutes) [*]iRedMail will prompt for firewall rules: Select 'N' iRedMail is now installed, take note of the url's given Screen Shot of Installed Configuration [*]Open iRedMail.tips for configuration specifics by typing the following command: nano /tmp/iRedMail/iRedMail.tips (Save this information incase you don't receive the email) [*]Now reboot and log back in! reboot Screen Shot of Reboot Upon reboot, you should notice "You have mail." You've just installed iRedMail! Feel accomplished yet? Create a Secure SSL Certificate For tutorial purposes we will use InstantSLL for a free certificate Create a Certificate Signing Request by typing the following command: cd /etc/sslopenssl req -out mail.yourdomain.com.csr -new -newkey rsa:2048 -nodes -keyout mail.yourdomain.com.key You will be prompted for information about your certificate, fill them out as requested. The 'extra' attributes are not required (Do not give a challenge password) Screen Shot of Certificate Information [*]Open your Certificate Signing Request by typing the following command: nano mail.yourdomain.com.csr Screen Shot of CSR Results I have removed some information and replaced it with *'s for security purposes [*]Copy all of the information located here, into the CSR Box from InstantSSL. Select Apache-ModSSL from the server software drop-down, uncheck Opt in? Then click 'Next >' Screen Shot of CSR Box @ InstantSSL After InstantSLL validates your request (more steps) you will receive a .zip containing two files. [ mailyourdomain_com.ca-bundle and mail_yourdomain_com.crt] (Screen Shot of the files) _To rush the validation, you can log into the comodo account you created and download the .zip of certificate files from your account panel. [*]Place both of these files in /etc/ssl on your server After unzipping the document, open each file with your favorite text editor. Copy and paste the information in each file into the same file name on your server. [*] Modify Apache's default-ssl to reflect these SSL Certificates Type the following command nano /etc/apache2/sites-available/default-ssl Replace the default information so that the following is set SSLCertificateFile /etc/ssl/mail_yourdomain_com.crt SSLCertificateKeyFile /etc/ssl/mail.yourdomain.com.key SSLCACertificateFile /etc/ssl/mail_yourdomain_com.ca-bundle Please ensure to remove the # before SSLCACertificateFile and do not place the >> in the file, as these are indicators for your benefit Screen Shot of Default-SSL Configuration Use Ctrl+X and Y + Enter to save the adjustments [*] Modify Postfix and Dovecot's configuration files Postfix: nano /etc/postfix/main.cf Screen Shot of Postfix main.cf Under #TLS Parameters change: smtpd_tls_cert_file = /etc/ssl/mail_yourdomain_com.crt and smtpd_tls_key_file = /etc/ssl/mail.yourdomain.com.key [*]Dovecot: nano /etc/postfix/main.cf Screen Shot of Dovecot main.cf Under # SSL: Global settings change: ssl = required verbose_ssl = yes (this is optional, but added for debug help) and, ssl_cert = </etc/ssl/mail_yourdomain_com.crt ssl_key = </etc/ssl/mail.yourdomain.com.key Use Ctrl+X and Y + Enter to save the adjustments [*] Reboot by issuing the command reboot Screen Shot of Reboot [*] Verify your SSL is working by visiting https://mail.yourdomain.com Depending on which browser/OS you are using, you will see a lock icon next to your URL similar to the screenshot Screen Shot of SSL Secured Page You have your very own SSL Secured Address! Configure iRedAdmin Accounts Login to iRedAdmin and configure accounts https://mail.yourdomain.com/iRedAdmin Username:postmaster@yourdomain.com and Password: password (or whatever you set earlier, located in iRedMail.tips) then click [Login] This is your main mail server admin panel or configuration portal Screen Shot of Login Screen [*]Change your password! Click Preferences in the top right, then select Password to the right of General Screen Shot of Preferences After changing your password, I would also recommend removing your Mailbox Quota [0] and changing your User ID to [admin] or your preference Screen Shot of Preferences Settings Logout and back in [*]Disable Greylisting! This is my personal preference, it's only given me problems in the past iRedAPD (aka Cluebringer) Go to https://mail.yourdom...isting-main.phpIt will prompt for a Username and Password. This is the same as your postmaster address (eg. postmaster@yourdomain.com:password) Screen Shot of Cluebringer Login Once here, select Default Inbound, Action >> Delete [*]Disable Policies Also personal preferene [*]Go to https://mail.yourdom...policy-main.php Select the policy of your choice (Action Change) On the policy edit page, Disable < Yes [*] Create a new email address. Return to https://mail.yourdomain.com and login Select [+Add...] > >User Mail Address* [anythingyouwish]@[yourdomain.com] New password* [********] Confirm new password [********] Display Name [not required but suggested] Mailbox Quota [-99999] Determine Mailbox Quota depending on the user of the account, and your server's storage space (Thankfully DigitalOcean is resizable!) Screen Shot of New User Preferences You just created your first email account on your new server! Using your new email! After all of that, you finally get to use your email server for personal email, or professional! Webmail Access https://mail.yourdomain.com This is the url for you to be able to access your e-mail from any web-enabled device!Enter the Username and Password you just created Screen Shot of L/P For Webmain Access [*]You should now be welcomed by a beautiful roundcube webmail user interface. Screen Shot of Roundcube Webmail [*]From this point I typically like to test the send/receive functions. Select Compose +, to create a new message to whomever you like. Before sending, open your SSH client with the following command: tail -f mail.log mail.err for debugging! I would also suggest doing the same by sending an email to your new account from another email address. [*] Mail Client Coming Soon Lighthalzen 1 Share Link to comment https://www.neowin.net/forum/topic/1157620-free-perfect-mail-server-detailed-tutorial/ Share on other sites More sharing options...
Recommended Posts