学习如何在 Linux 中使用 Postfix 设置邮件服务
您可能希望设置自己的 Linux 邮件服务器的原因有很多。如今,越来越多的人被迫修复他们的电子邮件 – 如果它曾经出现故障的话。Postfix 是一个 MTA(邮件交换代理),一种用于发送和接收邮件的软件。它是 Wietse Venema 的邮件服务器,最初诞生于 IBM 研究,作为广泛使用的 Sendmail 应用程序的替代方案。现在在 Google 工作的 Wietse 继续支持 Postfix。本文介绍了 – 如何在 Linux 中使用 postfix 设置邮件服务。
要安装 Postfix 并测试邮件实用程序,请使用以下命令 –
$ sudo apt-get install mailutils
示例输出应如下所示 –
Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: linux-headers-4.4.0-53 linux-headers-4.4.0-53-generic linux-image-4.4.0-53-generic linux-image-extra-4.4.0-53-generic linux-signed-image-4.4.0-53-generic Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: libgsasl7 libkyotocabinet16v5 libmailutils4 libntlm0 mailutils-common postfix Suggested packages: mailutils-mh mailutils-doc procmail postfix-mysql postfix-pgsql postfix-ldap postfix-pcre sasl2-bin dovecot-common postfix-cdb postfix-doc The following NEW packages will be installed: libgsasl7 libkyotocabinet16v5 libmailutils4 libntlm0 mailutils mailutils-common postfix
在安装过程中,它将提示以下屏幕以配置 postfix –
单击“确定”按钮继续。现在,它将提示以下屏幕以配置邮件配置的一般类型,如下所示 –
选择互联网站点并单击“确定”按钮。默认情况下,它将系统名称作为系统邮件名称,如下面的屏幕所示 –
根据需要更改系统邮件名称。例如,我们已将 tutorialspoint.com 作为系统邮件名称。现在单击“确定”按钮。完成安装过程后,您需要配置 postfix。为此,请使用以下命令打开配置文件。
$sudo nano /etc/postfix/main.cf
示例输出应如下所示 –
# See /usr/share/postfix/main.cf.dist for a commented, more complete version # Debian specific: Specifying a file name will cause the first # line of that file to be used as the name. The Debian default # is /etc/mailname. #myorigin = /etc/mailname smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu) biff = no # appending .domain is the MUA's job. append_dot_mydomain = no # Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h readme_directory = no
现在查找inet_interfaces = all
并将其重新更改为inet_interfaces = loopback-only
。示例输出应如下所示 –
mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = loopback-only inet_protocols = all
通过点击 Ctrl+O 保存文件,并通过点击 Ctrl+X 关闭文件。现在使用以下命令重新启动 Postfix –
$ sudo service postfix restart
要获取有关 postfix 的更多信息,请使用以下命令 –
$ man postfix
示例输出应如下所示 –
POSTFIX(1) General Commands Manual POSTFIX(1) NAME postfix - Postfix control program SYNOPSIS postfix [-Dv] [-c config_dir] command DESCRIPTION This command is reserved for the superuser. To submit mail, use the Postfix sendmail(1) command. The postfix(1) command controls the operation of the Postfix mail sys‐ tem: start or stop the master(8) daemon, do a health check, and other maintenance. By default, the postfix(1) command sets up a standardized environment and runs the postfix-script shell script to do the actual work. However, when support for multiple Postfix instances is configured, postfix(1) executes the command specified with the multi_instance_wrap‐ per configuration parameter. This command will execute the command for each applicable Postfix instance.
使用以下命令通过 Postfix 发送邮件,如下所示 –
echo "Tutorials Point originated from the idea that there exists a class of readers who respond better to online content and prefer to learn new skills at their own pace from the comforts of their drawing rooms." | mail -s "About us" [email protected]
现在检查您的收件箱或垃圾邮件文件夹以验证邮件。上述邮件的示例输出应如下所示 –
在以上文章中,我们学习了 – 学习如何在 Linux 中使用 postfix 设置邮件服务。在我们的下一篇文章中,我们将提供更多基于 Linux 的技巧和提示。继续关注!