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 an 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 .bash_rc 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"
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 file similar to the following:
# Email Address Destination testguy@anchor.com.au testguy testgirl@anchor.com.au testgirl support@anchor.com.au testguy, testgirl steve@anchor.com.au steve@example.com
As you can see there are two columns:
The first column is defined as the “Email Address” this will allow you to define an email address that you wish to accept email for on the server.
The second column is the destination for the email. This essentially tells that mail server what to do with the email.
Anything starting with a # is ignored by the mail server (this can be used for keeping short notes for future reference)
Some examples of valid values that can be added to this file:
Example 1:
testguy@anchor.com.au testguy
In this first example, all email will be accepted for testguy@anchor.com.au and delivered to the mailbox named: testguy
For this to work, the mailbox will also have need to be created (as per page 1).
Example 2:
support@anchor.com.au testguy, testgirl
In this example, any email sent to support@anchor.com.au will be delivered to two separate mailboxes; testguy and testgirl
Once again, both of these mailboxes would need to exist on the server for this to work.
Example 3:
steve@anchor.com.au steve@example.com
In this example, all email for steve@anchor.com.au will be sent to an external mail server. This is also valid in this file and will work as expected.
Once the changes have been made you will need to edit 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.
