How to configure a mail server on a Starlight™ Virtual Machine

To open port 25 on your Virtual Machine (VM), go to Starlight Manager > choose the "Mail Bridge" Tab > press the ‘Add Mail Bridge’ button.

Once the PTR record is set and port 25 is enabled, you can set up your preferred SMTP server. Below are examples for Postfix, Exim, and Sendmail. Use the VM IP shown in your Starlight Manager, and make sure your domain name for the PTR record matches your sender domain (e.g., mail.example.com).

Installing and configuring Postfix

# for Debian/Ubuntu

sudo apt update

sudo apt install postfix mailutils -y



# for Almalinux/Rocky/Cloudlinux/EL

# check RPM-based distros to check

# if Postfix is installed

rpm -qa | grep postfix

# if it is not, run the command below to install Postfix

sudo dnf install postfix



When Postfix is installed, you can start the service and make sure it starts after your server is rebooted:

sudo systemctl start postfix

sudo systemctl enable postfix

Then, you can configure the service. All options needed for the service are located in the /etc/postfix directory, and the main configuration file is /etc/postfix/main.cf

Run the sudo nano /etc/postfix/main.cf command to start editing the main configuration file and add or update these lines:

inet_interfaces = all

# myhostname declares mail server’s hostname

myhostname = mail.example.com

# mydomain declares the domain that actually handles emails

domain = example.com

# mail_spool_directory declares the directory where mailbox files are placed

mail_spool_directory = /var/mail

myorigin = /etc/mailname

mydestination = $myhostname, localhost.$mydomain, localhost

relayhost =

inet_protocols = all

smtp_banner = $myhostname ESMTP



Restart Postfix to apply the changes:

sudo systemctl restart postfix



Test sending mail:

echo "Test message" | mail -s "Test Email" user@recipient.com

Installing and configuring Exim 4

# for Ubuntu/Debian

sudo apt update

sudo apt install exim4 -y



The command below displays a wizard user interface for configuring the software. It allows users to decide if Exim needs to split its configuration across multiple files or to store it in one file:

sudo dpkg-reconfigure exim4-config

If the first option is used, the configuration will be stored in the /etc/exim4/conf.d subdirectories. If one configuration file is chosen, it will be /etc/exim4/exim4.conf

When all configurations are done, run systemctl restart exim4so the changes take effect.

Edit /etc/exim4/update-exim4.conf.conf to ensure:

# dc_local_interfaces declares your mail service IP (e.g. 203.0.113.10)

dc_local_interfaces='203.0.113.10'

# dc_readhost declares your system mail name

dc_readhost='example.com'

# dc_other_hostnames declares system hostname

dc_other_hostnames='mail.example.com'



Restart Exim to apply the changes:

sudo systemctl restart exim4


Test email delivery by running the command below:

echo "Mail test" | mail -s "Exim Test" user@recipient.com

Installing and configuring Sendmail

# for Ubuntu/Debian

sudo apt update

sudo apt install sendmail sendmail-bin -y

# for Almalinux/Cloudlinux/RHEL

yum install sendmail sendmail-cf mailutils


The main configuration file of Sendmail is /etc/mail/sendmail.cf. Avoid editing this file directly. If there is a need to edit the configuration, edit the /etc/mail/sendmail.mc file instead, back up the original config file, and use one of the following alternatives to generate a new config file:

1) Use the included makefile /etc/mail to create a new config:

make all -C /etc/mail/

 

All generated files in /etc/mail will be regenerated if there is a need.

2) Alternatively, you may use the m4macro processor to create a new /etc/mail/sendmail.cf. The m4macro processor is not installed by default. Before using it to create /etc/mail/sendmail.cf, install the m4package as root:

# for Almalinux/Cloudlinux/RHEL

yum install m4


# for Ubuntu/Debian

apt install m4


The following Sendmail configuration files are located in the /etc/mail/directory:

  • access- specifies which systems can use Sendmail for outbound mail

  • domaintable- domain name mapping

  • local-host-names - aliases for the server host

  • mailertable- instructions that override routing for the particular domains

  • virtusertable- specifies a domain-specific form of aliasing, allowing multiple virtual domains to be hosted on the machine.


Below, you may see the examples of how the configuration files can be edited:

# editing the server host aliases:

echo "mail.example.com" > /etc/mail/local-host-names


# binding to Mail IP by editing /etc/mail/sendmail.mc:
DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Addr=203.0.113.10')dnl


# rebuilding the config:
sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf


# testing:

echo "Hello from Sendmail" | mail -s "Sendmail test" user@recipient.com

Several of the aforementioned configuration files must store their information in database files before any changes can take effect. To include any changes made in the configuration files, run the makemap hash /etc/mail/<name> < /etc/mail/<name>command as root. Here, <name> represents the name of the configuration to be updated.

Restart the Sendmail process by running the systemctl restart sendmail command.

A valid email is required