Debian10.2配置邮件服务器postfix+dovecot

本文详细介绍如何使用postfix和dovecot在中小局域网内搭建邮件服务,包括服务器组件安装、配置环境、参数调整及客户端配置步骤,实现邮件的发送与接收。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

解决中小局域网内邮件服务的问题,使用postfix与dovecot搭建SMTP和POP3服务器。

安装服务器组件

apt-get install –y postfix dovecot-pop3d mailutils

其中mailutils,是mail命令程序。如果不用命令行方式的话,可以不安装。

安装postfix的时候,会提示要求选择邮件服务器类型,这里选择Internet Site。

No configuration:
    Should be chosen to leave the current configuration unchanged.
Internet site:
    Mail is sent and received directly using SMTP.
Internet with smarthost:
    Mail is received directly using SMTP or by running a utility such as fetchmail. Outgoing mail is sent using a smarthost.
Satellite system:
    All mail is sent to another machine, called a 'smarthost', for delivery.
Local only:
    The only delivered mail is the mail for local users. There is no network.

进而会提示输入邮件域名,这里按需填写。(例如mail.wa.cn)

配置环境

邮件服务器IP地址=192.168.31.73,测试用户名为test(密码123)、duanjsh(密码123)。测试PC机一台,与邮件服务器三层可达。

修改/etc/hosts,把相应域名加入到hosts中。

vim /etc/hosts 
192.168.31.73   mail.wa.cn wa.cn

检查一下/etc/mailname的值是不是安装时配置的。

cat /etc/mailname
mail.wa.cn

创建一个账户进行测试:

mkdir -p /home/test
useradd test -d /home/test -g users -s /bin/bash
chown test:users /home/test -R
passwd test

postfix配置

postfix的主要配置文件是/etc/postfix/main.cf,这里按需修改。我把修改项压缩到0或1步,即修改其中的mydestination项。后面会提到这项。

dovecot配置

dovecot配置都在/etc/dovecot/下,我修改了2处:

vim /etc/dovecot/conf.d/10-auth.conf
#disable_plaintext_auth修改为
disable_plaintext_auth = no

vi /etc/dovecot/conf.d/10-ssl.conf
#ssl修改为
ssl = no

重启两个服务

service dovecot restart
service postfix restart

安装配置客户端

可以采用foxmail来作为邮件客户端。

新建账号,其他邮箱,手动设置。接收服务类型选择POP3,用户名和密码填邮件服务器内的具体用户名(test)与密码(123)。POP3和SMTP服务器地址都填写具体的服务器地址,这里假设是192.168.31.73,端口110和25均为默认。

账号管理,Email地址修改为test@mail.wa.cn。

测试

当foxmail同时配置多个用户时,在左侧可以使用A账号发邮件给B账号。

在main.cf中destination配置了mail.wa.cn,该postfix仅能接收mail.wa.cn,如果收件人是test@155.com,发送就会失败。这个destination配置项,仅监察收件人,不检查发件人。如果155.com域名不在destination中,使用test@155.com这个邮件地址作为发起方,是可以的。如果要postfix接收多个域名,就要修改destination项。

telnet测试

如果没有foxmail这种客户端,也可以使用telnet的几个命令进行测试:helo、mail from、rcpt to、data。

root@deb10:/etc/postfix# telnet localhost  25
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 deb10 ESMTP Sendmail 8.15.2/8.15.2/Debian-14~deb10u1; Sun, 9 Feb 2020 18:08:20 +0800; (No UCE/UBE) logging access from: localhost(OK)-localhost [127.0.0.1]
helo abc
250 deb10 Hello localhost [127.0.0.1], pleased to meet you
mail from:root@localhost    
250 2.1.0 root@localhost... Sender ok
rcpt to:duanjsh@localhost
250 2.1.5 duanjsh@localhost... Recipient ok
data
354 Enter mail, end with "." on a line by itself
hey duan, you are so smart!
.
250 2.0.0 019A8K2I002817 Message accepted for delivery

 

### 如何在 Debian 12 上安装和配置 Postfix 邮件服务器 #### 准备工作 为了确保系统的安全性和稳定性,在开始之前应该更新软件包列表并升级已有的软件包到最新版本。 ```bash sudo apt update && sudo apt upgrade -y ``` #### 安装必要的软件包 需要两个主要的软件包来设置Postfix邮件服务器:`postfix` 和 `mailutils`。前者是实际的MTA (Mail Transfer Agent),后者包含了发送测试电子邮件所需的工具和其他辅助程序[^3]。 ```bash sudo apt install postfix mailutils -y ``` #### 配置 Postfix 安装过程中会弹出一个窗口询问关于Postfix的主要配置选项,可以选择“Internet Site”,这适用于大多数情况下的单台主机对外提供服务的情形。接着输入域名作为系统邮件名称,比如 example.com。 如果错过了这个界面也不必担心,可以通过重新运行以下命令来进行初始配置: ```bash sudo dpkg-reconfigure postfix ``` 对于更详细的自定义化设定,则需编辑主配置文件 `/etc/postfix/main.cf` 。例如要指定监听地址、我的网络范围或是添加额外的服务特性等都可以在这个文件里完成修改[^1]。 #### 测试发信功能 通过简单的命令行方式可以验证是否成功设置了基本的邮件传输能力: ```bash echo "This is the body of the email" | mail -s "Test Email Subject" recipient@example.net ``` 请注意替换上面命令中的收件人邮箱地址为有效的外部接收者以便确认外网可达性。 #### 增强安全性与功能性 考虑到现代互联网环境的安全需求,建议进一步增强SMTP认证机制和支持加密通信协议(TLS/SSL)等功能。另外还可以考虑集成SPF, DKIM这样的防伪技术以提高发出邮件的信任度[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值