Adding a new domain to postfix mail server on your dedicated server
This document will provide a list of instructions on how to configure email on your dedicated server.
There are a couple of definitions that you should be familiar with:
- MAILBOX – this is the location which most email will end up going. Typically this is where mail will be stored and will be retrieved by the end user using a username and password combination. Mail can be accessed via a mail program (such as Outlook or Thunderbird) using a POP3 or IMAP connection or alternatively through web mail.
EMAIL ADDRESS – this is address that is given out to customers and will take the format: email@example.com
- MAIL TABLE – This is a text file that is used to define the email addresses that the server will accept email for and what it will be with the message.
To configure this you will need to connect to the server using SSH.
If you need help connecting via SSH, see our SSH support article
The following instructions rely on a series of bash aliases, if these are not already configured on your server, you will need to add the following entries to the .bashrc file in the home directory of the user account on your server:
alias edmail="sudo cp /etc/postfix/virtual /etc/postfix/backup/virtual-`date -I`;sudo nano /etc/postfix/virtual; sudo /usr/sbin/postmap /etc/postfix/virtual" alias newmb="sudo /usr/sbin/useradd -m -g users -s /sbin/ftponly" alias lockmb="sudo /usr/sbin/usermod -L" alias unlockmb="sudo /usr/sbin/usermod -U" alias passwd="sudo /usr/bin/passwd"
The edmail alias makes use of a backup directory, so create that also:
sudo mkdir /etc/postfix/backup
Adding a new mailbox
In order to add a mailbox a new user needs to be added to the server.
This can be done using the following command:
Where username is replaced by the name of the user that you would like to add.
You will then need to set the password for the account using the following:
Once again, replace the USERNAME with the name of the users password you would like to reset.
All mail configuration is kept in a flat text file, this can be accessed using the following command when connected via ssh.
This will bring up a large block of comments describing what can go in this file.
At the bottom you can add your own alias entries:
# Domain/Email Address Destination example.com OK firstname.lastname@example.org testguy email@example.com testgirl firstname.lastname@example.org testguy, testgirl email@example.com firstname.lastname@example.org
Any lines that start with a # are ignored by the mail server (this can be used for keeping short notes for future reference).
Let's take a look at each of the following lines in turn.
This tells the mail server that it will be handling mails sent to the example.com domain. Without this line, the mail server will simply reject emails sent to users at this domain.
email@example.com testguy firstname.lastname@example.org testgirl
These lines say all emails sent to email@example.com should be delivered to the "testguy" mailbox, and emails sent to firstname.lastname@example.org should be delivered to the "testgirl" mailbox.
email@example.com testguy, testgirl
This line demonstrates how mail can be sent to multiple recipients: email sent to firstname.lastname@example.org will be delivered to both the mailboxes "testguy" and "testgirl".
You can configure your server to forward emails to external servers. This line defines a mail forward for email@example.com to the address firstname.lastname@example.org.
Once the changes have been made you will need to exit the editor (CTRL-X) selecting Y to save changes.
Important: Make sure these changes are 100% accurate as they will be effective immediately.
Any email which is not defined within the mail table will be rejected for delivery.
In order to lock a mailbox (prevent a user from logging in), the following command should be used:
Replacing USERNAME with the name of the mailbox you wish to lock.
Keep in mind that if the entry is still in the mail table then this mailbox will still receive email, just no one will be able to log in to check this.
If you would like to unlock a mailbox, the following command can be used:
Once again replacing the USERNAME section.