Linux学习-邮件服务(安装postfix)

本文详细介绍了Postfix邮件服务器的安装配置过程,包括解决安装过程中遇到的问题、基本概念解释及核心配置步骤。同时,还提供了通过telnet测试邮件发送的方法。

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

安装时遇到的问题
问题1:

[root@lotus postfix-2.11.11]# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I /usr/include/sasl -DUSE_TLS ' 'AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto'
make -f Makefile.in MAKELEVEL= Makefiles
(echo "# Do not edit -- this file documents how Postfix was built for your machine."; /bin/sh makedefs) >makedefs.tmp
No <db.h> include file found.
Install the appropriate db*-devel package first.
make: *** [Makefiles] Error 1
make: *** [makefiles] Error 2

解决方法
[root@lotus postfix-3.1.15]# yum install db4-devel -y

报错:
postfix/postfix-script: warning: not set-gid or not owner+group+world executable: /usr/sbin/postqueue
postfix/postfix-script: warning: not set-gid or not owner+group+world executable: /usr/sbin/postdrop
解决方法:

[root@lotus ~]# chmod g+s /usr/sbin/postqueue
[root@lotus ~]# chmod g+s /usr/sbin/postdrop

邮件基本信息介绍
SMTP(Simpe Mail Transfer Protocol)简单邮件传输协议
POP3(Post Office Protocol)邮局协议
IMAP4(Internet Mail Access Protocol)互联网邮件访问协议
UUCP(Unix to Unix Copy)Uninx主机复制文件的协议

SMTP(25/tcp)
每个服务器都有一个目录存放邮件,每个用户邮件都是一个以用户名命名的文件
用户看到的邮件会保存到用户家目录下mbox

邮件传输:MT(Mail Transfer)从发送方发送到对方主机的邮件主机的过程
邮件投递:MD(Mail Delivery)从主机发送到用户邮箱的过程
邮件用户:MU(Mail User)
邮件用户代理:MUA(Mail User Agent)
LMTP(local Mail Transfer Protocol)本地邮件传输协议
邮件传输代理:MTA(Mail Transfer Agent)
用户写好邮件后,通过SMTP协议传递至本地邮件服务器,邮件服务器通过MTA判断是否为本地用户邮件,如为本地用户,则通过lmtp直 接放至用户邮箱,如为远程用户,则通过SMTP协议发送到远程用户邮件服务器。
邮件投递代理:MDA(Mail Delivery Agent)当邮件到达远程用户邮件服务器时,邮件服务器会调用MDA进行邮件投递
用户如何查看邮件:通过MUA(Mail User Agent)从邮箱获取邮件查看,并保存至用户家目录下

SASL(Simple Authentication Secure Layer)简单认证安全层:完成邮件用户验证
MRA(Mail Retrieval Agent)邮件取回代理–POP3或IMAP,从邮箱取回,并传递给用户
WebMail
LDAP(LightWeight Directory Access Protocol)轻量级目录访问协议:读取速度很快,写入速度很慢
常用的邮件服务器和客户端软件
MTA:
sendmail: 单体结构,SUID,配置文件语法复杂(m4编写)
qmail:
postfix:模块化设计,安全,与sendmail兼容,效率高
exim:
exchange:window用,异步消息协作平台
MDA:
procmail:
maildrop:
MRA(pop3,imap4):
cyrus-imap
dovecot
MUA:
Outlook Express,Outlook
Foxmail
ThunderBird
Evolution
mutt(文本界面)
WebMail:
Openwebmail
Squirrelmail
ExtMail(Extman)
SASL:
cyrus-sasl
courier-authlib
编译安装postfix

  1. 添加用户postfix和postdrop
[root@lotus postfix-3.1.15]# groupadd -g 2526 postdrop
[root@lotus postfix-3.1.15]# useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop
[root@lotus postfix-3.1.15]# groupadd -g 2525 postfix
[root@lotus postfix-3.1.15]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
  1. 下载postfixpostfix,并安装postfix
[root@lotus ~]# tar xf postfix-2.11.11.tar.gz 
[root@lotus ~]# cd postfix-2.11.11
#DHAS_MYSQL:mysql头文件
#DUSE_CYRUS_SASL:SASL头文件
#-DUSE_TLS :支持smtps基于SSL
#-DUSE_SASL_AUTH:支持SASL认证
#AUXLIBS:库文件
#-lz :压缩库文件
#-lm:模块库文件
#-lsasl2:sasl2的库文件
#-lssl:ssl的库文件
#-lcrypto:加密库文件
#注:头文件和库文件根据安装程序的目录来决定,编译安装和rpm安装目录可能会不同
[root@lotus postfix-2.11.11]# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I /usr/include/sasl -DUSE_TLS ' 'AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto'
[root@lotus postfix-2.11.11]# make
[root@lotus postfix-2.11.11]# make install 
/bin/sh postfix-install

    Warning: if you use this script to install Postfix locally,
    this script will replace existing sendmail or Postfix programs.
    Make backups if you want to be able to recover.

    Before installing files, this script prompts you for some definitions.
    Most definitions will be remembered, so you have to specify them
    only once. All definitions should have a reasonable default value.

Please specify the prefix for installed file names. Specify this ONLY
if you are building ready-to-install packages for distribution to OTHER
machines. See PACKAGE_README for instructions.
install_root: [/] /

Please specify a directory for scratch files while installing Postfix. You
must have write permission in this directory.
tempdir: [/root/postfix-2.11.11] /tmp/postfix

Please specify the final destination directory for installed Postfix
configuration files.
config_directory: [/etc/postfix] /etc/postfix

Please specify the final destination directory for installed Postfix
administrative commands. This directory should be in the command search
path of adminstrative users.
command_directory: [/usr/sbin] /usr/sbin

Please specify the final destination directory for installed Postfix
daemon programs. This directory should not be in the command search path
of any users.
daemon_directory: [/usr/libexec/postfix] /usr/libexec/postfix

Please specify the final destination directory for Postfix-writable
data files such as caches or random numbers. This directory should not
be shared with non-Postfix software.
data_directory: [/var/lib/postfix] 

Please specify the final destination directory for the Postfix HTML
files. Specify "no" if you do not want to install these files.
html_directory: [no] /www/postfix 

Please specify the owner of the Postfix queue. Specify an account with
numerical user ID and group ID values that are not used by any other
accounts on the system.
mail_owner: [postfix] 

Please specify the final destination pathname for the installed Postfix
mailq command. This is the Sendmail-compatible mail queue listing command.
mailq_path: [/usr/bin/mailq] 

Please specify the final destination directory for the Postfix on-line
manual pages. You can no longer specify "no" here.
manpage_directory: [/usr/local/man] 

Please specify the final destination pathname for the installed Postfix
newaliases command. This is the Sendmail-compatible command to build
alias databases for the Postfix local delivery agent.
newaliases_path: [/usr/bin/newaliases] 

Please specify the final destination directory for Postfix queues.
queue_directory: [/var/spool/postfix] 

Please specify the final destination directory for the Postfix README
files. Specify "no" if you do not want to install these files.
readme_directory: [no] 

Please specify the final destination pathname for the installed Postfix
sendmail command. This is the Sendmail-compatible mail posting interface.
sendmail_path: [/usr/sbin/sendmail] 
  1. postfix的启动信息/var/log/maillog文件中
[root@lotus ~]# tail /var/log/maillog
Apr 18 00:25:02 lotus postfix/postfix-script[27300]: stopping the Postfix mail system
Apr 18 00:25:02 lotus postfix/master[27280]: terminating on signal 15
Apr 18 00:25:05 lotus postfix/postfix-script[27351]: warning: not owned by root: /var/spool/postfix
Apr 18 00:25:05 lotus postfix/postfix-script[27355]: warning: not owned by root: /var/spool/postfix/pid
Apr 18 00:25:05 lotus postfix/postfix-script[27374]: starting the Postfix mail system
Apr 18 00:25:05 lotus postfix/master[27376]: daemon started -- version 2.11.11, configuration /etc/postfix
Apr 18 00:26:42 lotus postfix/postfix-script[27387]: stopping the Postfix mail system
Apr 18 00:26:42 lotus postfix/master[27376]: terminating on signal 15
Apr 18 00:26:45 lotus postfix/postfix-script[27459]: starting the Postfix mail system
Apr 18 00:26:45 lotus postfix/master[27461]: daemon started -- version 2.11.11, configuration /etc/postfix
  1. postfix的配置文件
    postfix模块化
    master:/etc/postfix/master.cf
    pickup:分捡进程
    cleanup:清理进程
    qmgr:队列管理器
    defer:延迟发送队列管理器
    rewrite:重写
    verify:验证器
    flush:清理器

     main:/etc/postfix/main.cf
     参数 = 值   注:参数必须顶格(绝对行首)来写,以空白字符开始的行认为是上一行的延续
    

postconf:配置postfix
-d:显示默认的配置
-n:显示修改了的配置
-m:所支持的查找表类型
-A:客户端支持的SASL插件类型
-a:服务器端支持的SASL插件类型
-e parameter=value:更改某参数配置信息,并保存至main.cf文件中

[root@lotus ~]# postconf -m
btree
cidr
environ
fail
hash
internal
memcache
mysql
nis
pcre
proxy
regexp
socketmap
static
tcp
texthash
unix
[root@lotus ~]# postconf -A
cyrus

smtp客户端向smtp服务器端发送邮件过程:

  1. 由于smtp服务是基于TCP/IP协议,需先进行TCP/IP三次握手
  2. 握手成功后,由客户端向服务器发送helo,服务器收到客户端的连接请求后,回送确认信息
  3. 客户端收到服务器的确认信息后,将发件人信息(mail from)发送至smtp服务器,服务器回送确认信息,说明发件人信息已收到
  4. 客户端接着向服务器发送收件人信息(rcpt to ),服务器收到后,回送确认信息
  5. 接着客户端向服务器发送正文信息,并以【.】结尾表示正文已结束
  6. 此时服务器就开始向外投递邮件。
    smtp状态码:
    1xx:纯信息
    2xx:正确
    3xx:上一步操作尚未完成,需要继续补充
    4xx:暂时性错误
    5xx:永久性错误
    smtp协议命令:
    helo(smtp协议)
    mail from:发件人
    rcpt to:收件人
#通过telnet测试邮件发送
[root@lotus ~]# telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 lotus.tye ESMTP Postfix
helo localhost
250 lotus.tye
mail from:root@tye.com
250 2.1.0 Ok
rcpt to:root
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
subject:How are you these days?
Are you gua le ma
【.】#此处点很重要,标志邮件结束
250 2.0.0 Ok: queued as 3B7E2BF2B7
#查看mail日志
[root@lotus ~]# tail /var/log/maillog
Apr 18 07:06:19 lotus postfix/postfix-script[2181]: starting the Postfix mail system
Apr 18 07:06:19 lotus postfix/master[2183]: daemon started -- version 2.11.11, configuration /etc/postfix
Apr 18 07:06:26 lotus postfix/smtpd[2187]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Apr 18 07:06:26 lotus postfix/smtpd[2187]: connect from localhost[127.0.0.1]
Apr 18 07:06:51 lotus postfix/smtpd[2187]: 3B7E2BF2B7: client=localhost[127.0.0.1]
Apr 18 07:09:28 lotus postfix/cleanup[2190]: 3B7E2BF2B7: message-id=<20210417230651.3B7E2BF2B7@lotus.tye>
Apr 18 07:09:28 lotus postfix/qmgr[2185]: 3B7E2BF2B7: from=<root@tye.com>, size=347, nrcpt=1 (queue active)
Apr 18 07:09:29 lotus postfix/local[2192]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Apr 18 07:09:29 lotus postfix/local[2192]: 3B7E2BF2B7: to=<root@lotus.tye>, orig_to=<root>, relay=local, delay=164, delays=164/0.29/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Apr 18 07:09:29 lotus postfix/qmgr[2185]: 3B7E2BF2B7: removed
You have mail in /var/spool/mail/root

#查看邮件内容
[root@lotus ~]# mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N  1 root@tye.com          Sun Apr 18 07:09  20/454   "How are you these days?"
& 1
Message  1:
From root@tye.com  Sun Apr 18 07:09:29 2021
Return-Path: <root@tye.com>
X-Original-To: root
Delivered-To: root@lotus.tye
subject:How are you these days?
Date: Sun, 18 Apr 2021 07:06:44 +0800 (CST)
From: root@tye.com
Status: R

Are you gua le ma.

postfix默认把本机的IP地址所在的网段识别为本地网络,并且为之中继邮件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值