In our previous article, we created an Exim email server and configure it to send email. We learnt how to create email accounts and the correct settings required to set up our email account in outlook. Now we’re going to focus on email aliases when using Exim. Email aliases are redirects for email. We can redirect local mail to other email addresses using the /etc/aliases file.
As well as routing email to different domains we can also route email for email accounts that don’t exist. If you want to route [email protected] and [email protected] to your email account you could use the aliases file to achieve this.
Forward Root Email
If you want to forward all emails for the root user to an email account you have created on your email server you just need to edit the /etc/aliases. Open up the file and add or change the very bottom line.
So, this would send all root email to the email account [email protected] Save and close the file then test your new configuration by sending a test mail to the root account using the command below. You should get the test email in your [email protected] email account
echo Hi | mailx root
Create New Email Aliases
As well as forwarding the root email to our email account we can forward mail for users that don’t have an email account on the server. We’re going to forward mail sent to [email protected] and [email protected] to our [email protected] email account.
# Aliases in this file will NOT be expanded in the header from Mail, but WILL be visible over networks or from /bin/mail. # >>>>>>>>>> The program "newaliases" must be run after >> NOTE >> this file is updated for any changes to >>>>>>>>>> show through to sendmail. # Basic system aliases -- these MUST be present. mailer-daemon: postmaster postmaster: root General redirections for pseudo accounts. bin: root daemon: root adm: root lp: root sync: root shutdown: root halt: root mail: root news: root uucp: root operator: root games: root gopher: root ftp: root nobody: root radiusd: root nut: root dbus: root vcsa: root canna: root wnn: root rpm: root nscd: root pcap: root apache: root webalizer: root dovecot: root fax: root quagga: root radvd: root pvm: root amandabackup: root privoxy: root ident: root named: root xfs: root gdm: root mailnull: root postgres: root sshd: root smmsp: root postfix: root netdump: root ldap: root squid: root ntp: root mysql: root desktop: root rpcuser: root rpc: root nfsnobody: root pcp: root ingres: root system: root toor: root manager: root dumper: root abuse: root newsadm: news newsadmin: news usenet: news ftpadm: ftp ftpadmin: ftp ftp-adm: ftp ftp-admin: ftp www: webmaster webmaster: root noc: root security: root hostmaster: root info: postmaster marketing: postmaster sales: postmaster support: postmaster noaccount: server noaccount1: server #trap decode to catch security attacks decode: root #Person who should get root's mail root: server
Here we have added the following code to the /etc/aliases file. This forwards all email for [email protected] and [email protected] to our [email protected] account. The accounts don’t have to exist in the email server for this to work.
noaccount: server noaccount1: server
You can test the changes by simulating email delivery like we did with the root account. When using Exim and email aliases you do not need to restart the mail server.
echo Hi | mailx noaccount
Forward Email To External Domains
We can also use the /etc/aliases file to send mail to domains not located on this server. Instead of specifying the local user, you can specify an email address. If you followed our Exim setup guide there is no further configuration needed to send to an offsite domain.
noaccount2: [email protected]
You might also like
More from Dedicated Servers
Cloud-init is a popular way to automate deployments of instances in a cloud or none cloud environment. To save having …
Ioncube Loaders are a piece of software that is used to protect the underlying code in PHP applications. Its aim …