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: username@domain.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:
newmb USERNAME
Where username is replaced by the name of the user that you would like to add.
Setting password
You will then need to set the password for the account using the following:
passwd USERNAME
Once again, replace the USERNAME with the name of the users password you would like to reset.
Mail Configuration
All mail configuration is kept in a flat text file, this can be accessed using the following command when connected via ssh.
edmail
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 testguy@example.com testguy testgirl@example.com testgirl support@example.com testguy, testgirl steve@example.com steve@elsewhere.com
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.
example.com OK
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.
testguy@example.com testguy testgirl@example.com testgirl
These lines say all emails sent to testguy@example.com should be delivered to the "testguy" mailbox, and emails sent to testgirl@example.com should be delivered to the "testgirl" mailbox.
support@example.com testguy, testgirl
This line demonstrates how mail can be sent to multiple recipients: email sent to support@example.com will be delivered to both the mailboxes "testguy" and "testgirl".
steve@example.com steve@elsewhere.com
You can configure your server to forward emails to external servers. This line defines a mail forward for steve@example.com to the address steve@elswhere.com.
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.
Locking Mailboxes
In order to lock a mailbox (prevent a user from logging in), the following command should be used:
lockmb USERNAME
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.
Unlocking Mailboxes
If you would like to unlock a mailbox, the following command can be used:
unlockmb USERNAME
Once again replacing the USERNAME section.