`

Postfix 快速指南 (转)

阅读更多

介绍

Postfix 是一种 Mail Transfer Agent 邮件传送代理 (MTA) 是 Ubuntu 缺省的邮件代理程序. 它在 Ubuntu 的 main 仓库, 意味着它将接收到安全方面的升级。 这个指南说明了如何安装和配置 postfix 和设置为一个使用安全连接的 SMTP 服务器。

 

安装

为了安装 Postfix 、 SMTP-AUTH 和 TLS 执行下列步骤:

apt-get install postfix libsasl2-2 sasl2-bin libsasl2-modules procmail

 

配置

 运行:

dpkg-reconfigure postfix
 

在被询问时,插入如下的内容 (如果你有一个域名的话,使用你的域名替换掉 server1.example.com ):

  • Internet Site
  • NONE
  • server1.example.com
  • server1.example.com, localhost.example.com, localhost
  • No
  • 127.0.0.0/8
  • Yes
  • 0
  • +
  • all

然后运行下面的命令:

postconf -e 'smtpd_sasl_local_domain ='
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'smtpd_sasl_security_options = noanonymous'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
postconf -e 'inet_interfaces = all'
echo 'pwcheck_method: saslauthd' >> /etc/postfix/sasl/smtpd.conf
echo 'mech_list: plain login' >> /etc/postfix/sasl/smtpd.conf

mkdir /etc/postfix/ssl
cd /etc/postfix/ssl/
openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024
chmod 600 smtpd.key
openssl req -new -key smtpd.key -out smtpd.csr
openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt
openssl rsa -in smtpd.key -out smtpd.key.unencrypted
mv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650

postconf -e 'smtpd_tls_auth_only = no'
postconf -e 'smtp_use_tls = yes'
postconf -e 'smtpd_use_tls = yes'
postconf -e 'smtp_tls_note_starttls_offer = yes'
postconf -e 'smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key'
postconf -e 'smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt'
postconf -e 'smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem'
postconf -e 'smtpd_tls_loglevel = 1'
postconf -e 'smtpd_tls_received_header = yes'
postconf -e 'smtpd_tls_session_cache_timeout = 3600s'
postconf -e 'tls_random_source = dev:/dev/urandom'
postconf -e 'myhostname = server1.example.com'

 文件 /etc/postfix/main.cf 现在看起来如下:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version

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

myhostname = server1.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = server1.example.com, localhost.example.com, localhost
relayhost =
mynetworks = 127.0.0.0/8
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
smtpd_sasl_local_domain =
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject _unauth_destination
smtpd_tls_auth_only = no
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt
smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

 重启 postfix 服务:

/etc/init.d/postfix restart
 

验证

验证通过 saslauthd 完成。

我们不得不调整一些东西使它工作的更好。 因为 Postfix 运行 chrooted 在 /var/spool/postfix 我们修改一些相对路径使其在一个假想的 root 下运行。 (例如. /var/run/saslauthd 变成 /var/spool/postfix/var/run/saslauthd ):

首先我们编辑 /etc/default/saslauthd 为了激活 saslauthd. 删除 # 于 START=yes 行的前面并且正在 PWDIR, PARAMS, 和 PIDFILE 行:

# This needs to be uncommented before saslauthd will be run automatically
START=yes

PWDIR="/var/spool/postfix/var/run/saslauthd"
PARAMS="-m ${PWDIR}"
PIDFILE="${PWDIR}/saslauthd.pid"

# You must specify the authentication mechanisms you wish to use.
# This defaults to "pam" for PAM support, but may also include
# "shadow" or "sasldb", like this:
# MECHANISMS="pam shadow"

MECHANISMS="pam"
 

笔记 : 如果你喜欢, 你可以使用 "shadow" 代替 "pam". 它将使用 MD5 来传输密码,这是一种更安全的做法。 用户名和密码的验证需要使用你服务器上的用户。

下一步, 我们更新 dpkg "状态" 于 /var/spool/portfix/var/run/saslauthd. saslauthd 初始化脚本来建立缺少的目录并拥有适当的权限:

dpkg-statoverride --force --update --add root sasl 755 /var/spool/postfix/var/run/saslauthd
 
dpkg-statoverride --force --update --add root sasl 755 /var/spool/postfix/var/run/saslauthd

 

最后,运行 saslauthd:

/etc/init.d/saslauthd start
 

测试

为了查看 SMTP-AUTH 和 TLS 是否正确运行,现在运行如下命令:

telnet localhost 25

当你连接到你的 postfix 邮件服务器后,输入

ehlo localhost

如果你看到如下行

250-STARTTLS
250-AUTH
 
250-STARTTLS
250-AUTH

在其它的中间, 所有的事情都在正常运行.

输入 quit 返回到系统终端.

 

一/测试SMTP发送邮件
[root@mail ~]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 mail.zpp.com ESMTP Postfix
helo localhost   //宣告客户端地址
250 mail.zpp.com
mail from:zpp001@zpp.com   //告知服务器发件人地址
250 2.1.0 Ok
rcpt to:zpp002@zpp.com     //告知服务器收件人地址
250 2.1.5 Ok
Data    //告知服务器要传送数据了
354 End data with <CR><LF>.<CR><LF>
subject:I Love You!    //主题
hello!
You are my super star! he he he !    //邮件内容以点结束
.
250 2.0.0 Ok: queued as 27ECCE01ED
Quit     //退出
221 2.0.0 Bye
Connection closed by foreign host.


二/测试POP3接收邮件
[root@mail ~]# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Dovecot ready.
user zpp002  //使用邮件用户“zpp002”登录
+OK
pass 123.com  //键入密码123.com
+OK Logged in.
List    //查看邮件列表
+OK 1 messages:
1 485
.
retr 1   //收取并查看第一封邮件内容
+OK 485 octets
Return-Path: <zpp001@zpp.com>
X-Original-To: zpp002@zpp.com
Delivered-To: zpp002@zpp.com
Received: from localhost (localhost.localdomain [127.0.0.1])
        by mail.zpp.com (Postfix) with SMTP id 27ECCE01ED
        for <zpp002@zpp.com>; Thu, 28 Jan 2021 03:57:40 +0800 (CST)
subject:I Love You!
Message-Id: <20210127195752.27ECCE01ED@mail.zpp.com>
Date: Thu, 28 Jan 2021 03:57:40 +0800 (CST)
From: zpp001@zpp.com
To: undisclosed-recipients:;
hello!
You are my super star! he he he !
.
quit
+OK Logging out.
Connection closed by foreign host.
 

其它 Postfix 指南

这些指南将教会你如何使用 Postfix 邮件服务器从基本的到高级设置。

Postfix 基础设置

Postfix 基本设置指南 将教会你 Posfix 的概念和如果做 Postfix 的基本设置和运行. 如果你是 Postfix 新手,推荐首先阅读这个指南.

Postfix 虚拟邮箱和病毒过滤

Postfix 虚拟邮箱和病毒过滤指南 将教会你如何设置一个虚拟邮箱使用 non-linux 帐号,每个用户将使用他们的 e-mail 地址和 POP3/IMAP 服务来验证 和 ClamSMTP 防毒软件过滤所有发进发出邮件已知的病毒.

Postfix 完整的问答

Postfix 完整虚拟邮件系统指南 将帮助你,如果你作为一个 ISP 管理一个大的虚拟域名,或者在一个大公司里面需要管理多个邮件域名,这个手册是适合的,你将看到如下的方法:

  • 基于 Web 的系统管理
  • 不限制数量的域名
  • 不需要系统帐号的虚拟邮件用户
  • 特定域名的用户帐号
  • 邮箱空间大小限制
  • Web 访问邮件帐号
  • Web 界面的修改用户帐号
  • IMAP 和 POP3 支持
  • Auto 回复
  • SMTP 验证
  • SSL 传输安全
  • 强大的 SPAM 过滤
  • Anti-Virus 过滤
  • 日志分析
分享到:
评论

相关推荐

    postfix权威指南 中文版

    postfix权威指南,O’Reilly系列丛书,POSTFIX权威指南中文版,文字版,排版与原书保持一致。全面了解postfix的绝对好书。 想要自己架设邮件服务器吗?如果sendmail让你头痛万分,现在你有更好的选择 —— Postfix...

    postfix权威指南(中文版).pdf

    postfix权威指南(中文版)

    POSTFIX权威指南

    POSTFIX权威指南

    postfix权威指南PDF

    如何编译、安装Postfix?如何用Postfix架设一台简单的邮件服务器?如何架设网域邮件网关?如何架设备用服务器?DNS与邮件系统的关系为何?mbox与maildir这两种邮箱格式有何不同?如何用同一台机器架设多个网域的邮件服务器...

    postfix 权威指南

    序 前言 第一章 简介 Postfix的起源与设计理念 E-mail与Internet Postfix的角色 Postfix的安全性 如何取得Postfix 第二章 基本概念 Unix的概念 E-mail的概念 第三章 Postfix的结构 Postfix的组件 邮件如何进入...

    postfix权威指南中文版

    总是下载CSDN上的资源,觉得应该分享一点,不知道是不是已经有了。讲解Postfix的书。

    POSTFIX权威指南(PDF)

    目前对 postfix 介绍最权威,最全面的书。简体中文,如果你需要使用 postfix 这是必经之路

    Postfix完全配置指南

    postfix extmail extman sasl imap mysql apache

    PostFix权威指南.md

    如何架设邮件服务器

    postfix完全手册 (共294页)

    本书内容以postfix 2.0版为准并涵盖过去曾经广为流传的某些重要旧版本与其的差异。

    Postfix 快速指南

    Postfix是ubuntu中默认的邮件传输代理(MTA).它是Ubuntu的main软件库中的一个软件.这意味着它拥有安全更新.这份指南告诉你如何安装及配置postfix并将其设置成一个使用安全连接的SMTP服务器.

    postfix权威指南

    This book introduce you how to configure the mail server postfix.It is a widely used mail server all over the world.

    postfix权威指南.part2

    postfix权威指南.part2 经典资料,postfix必看

    postfix-权威指南(postfix唯一中文指导教程)

    postfix唯一中文指导教程书,很经典,目前书店已经没有实体书本

    postfix权威指南.part1

    postfix权威指南.part1 经典的资料说明,postfix必看

    POSTFIX权威指南.part1.rar

    这学习posfix架设邮件服务器最详细的教材,分两个压缩包,请同时下载后一起打开。

    infix转POSTFIX算法

    infix转POSTFIX算法 infix转POSTFIX算法

    postfix完全指南

    是由postfix作者授权Kyle Dent写的这本书,应该是最全最权威的最完全的关于postfix的中文书籍了

    POSTFIX安装POSTFIX安装POSTFIX安装

    POSTFIX安装POSTFIX安装POSTFIX安装POSTFIX安装POSTFIX安装POSTFIX安装POSTFIX安装POSTFIX安装

Global site tag (gtag.js) - Google Analytics