如何在 Starlight™ 虚拟机上配置邮件服务器

要在您的虚拟机(VM)上打开 25 端口,请前往Starlight Manager > 选择“Mail Bridge”标签 > 点击“添加 Mail Bridge”按钮。

设置好 PTR 记录并启用 25 端口后,您可以配置首选的 SMTP 服务器。以下是PostfixEximSendmail的示例。请使用在VM IP中显示的Starlight Manager,并确保您的PTR 记录的域名与发件人域名一致(例如 mail.example.com)。

安装和配置 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



安装 Postfix 后,您可以启动服务,并确保服务器重启后自动启动:

sudo systemctl start postfix

sudo systemctl enable postfix

然后,您可以配置该服务。所有所需选项都位于/etc/postfix目录,主配置文件为/etc/postfix/main.cf

运行 sudo nano /etc/postfix/main.cf命令开始编辑主配置文件,并添加或更新以下内容:

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



重启 Postfix 以应用更改:

sudo systemctl restart postfix



测试发送邮件:

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

安装和配置 Exim 4

# for Ubuntu/Debian

sudo apt update

sudo apt install exim4 -y



以下命令将显示用于配置软件的向导界面。用户可以选择是否将 Exim 配置拆分为多个文件,或存储在一个文件中:

sudo dpkg-reconfigure exim4-config

如果使用第一个选项,配置将存储在/etc/exim4/conf.d子目录中。如果选择一个配置文件,它将被/etc/exim4/exim4.conf

完成所有配置后,运行systemctl restart exim4以使更改生效。

编辑/etc/exim4/update-exim4.conf.conf以确保:

# 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'



重启 Exim 以应用更改:

sudo systemctl restart exim4


通过运行以下命令测试邮件投递:

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

安装和配置 Sendmail

# for Ubuntu/Debian

sudo apt update

sudo apt install sendmail sendmail-bin -y

# for Almalinux/Cloudlinux/RHEL

yum install sendmail sendmail-cf mailutils


Sendmail 的主配置文件是/etc/mail/sendmail.cf。请避免直接编辑此文件。如需修改配置,请编辑/etc/mail/sendmail.mc文件,备份原始配置文件,并使用以下任一方法生成新配置文件:

1)使用自带的 makefile/etc/mail创建新配置:

make all -C /etc/mail/

 

如有需要,/etc/mail中的所有生成文件都将被重新生成。

2)或者,您可以使用m4宏处理器来创建新的/etc/mail/sendmail.cf。默认未安装m4宏处理器。要使用它创建/etc/mail/sendmail.cf,请以 root 身份安装m4软件包:

# for Almalinux/Cloudlinux/RHEL

yum install m4


# for Ubuntu/Debian

apt install m4


以下 Sendmail 配置文件位于/etc/mail/目录下:

  • access- 指定哪些系统可以使用 Sendmail 发送外部邮件

  • domaintable- 域名映射

  • local-host-names- 服务器主机的别名

  • mailertable- 用于特定域的路由覆盖说明

  • virtusertable- 指定域专用别名形式,允许在同一台机器上托管多个虚拟域。


以下是配置文件可编辑方式的示例:

# 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

上述部分配置文件在更改生效前,必须将信息存储到数据库文件中。要使配置文件的更改生效,请以 root 身份运行makemap hash /etc/mail/<name> < /etc/mail/<name>命令。其中,<name> 表示要更新的配置名称。

通过运行systemctl restart sendmail命令重启 Sendmail 进程。

需要提供有效的电子邮箱