一、DNS配置

类型

名称    TTL 
 A mail  128.199.254.32  1小时 

MX

 @ mail.example.com(优先:10) 1小时 

TXT

@  v=spf1 mx:mail.example.com ip4:128.199.254.32 ~all  1小时 
 TXT mail._domain  keyv=DKIM1;k=rsa; p=MIGfMA0GCSqGSI…  1小时 

 

其中可以先配置A和MX记录,

两个TXT记录用于“反垃圾邮件”,其中DKIM需要本机配置,后文会详细说明。


二、Postfix安装及配置

2.1 事先设置好hostname的话,Postfix可以自动配置好很多参数,节省时间。

# echo “example.com” > /etc/hostname

2.2 安装postfix

# apt update
# apt install mailutils

默认选项为Internet Siteexample.com 按回车。

2.3 基本配置

修改文件 /etc/postfix/main.cf

…

myhostname = mail.example.com

mydomain = example.com

…

mydestination = $myhostname, localhost.$mydomain, $mydomain

inet_interfaces = loopback-only

然后重启服务。

# systemctl restart postfix

2.4 现在已经可以发邮件了,测试一下看能不能收到。

$ echo “body of the email” | mail -s “subject line” your_email_address

2.5 (可选配置)使用TLS加密

三、反垃圾设置:SPFDKIMDMARC

3.1 SPF只是添加DNS记录即可,这里重点说一下DKIM的安装配置

# apt install opendkim opendkim-tools

3.2 编辑文件 /etc/opendkim.conf 追加如下配置到文件最下边:AutoRestart YesAutoRestartRate /1h

UMask
Syslog yes
SyslogSuccess Yes
LogWhy Yes Canonicalization relaxed/simple ExternalIgnoreList refile:/etc/opendkim/TrustedHosts
InternalHosts refile:/etc/opendkim/TrustedHosts
KeyTable refile:/etc/opendkim/KeyTable
SigningTable refile:/etc/opendkim/SigningTable Mode sv
PidFile /var/run/opendkim/opendkim.pid
SignatureAlgorithm rsa-sha256

UserID opendkim:opendkim
Socket inet:@localhost

3.3  编辑/etc/default/opendkim,注释掉原用的SOCKET配置,增加新配置:

SOCKET="inet:12301@localhost"

3.4 编辑/etc/postfix/main.cf, 增加如下配置:

milter_protocol =  milter_default_action = accept

其中, 当postfix版本为2.6+,milter_protocol=6; 版本为2.3到2.5,milter_protocol=2;

查看postfix版本信息:

$ postconf -d | grep mail_version

如果已经有smtpd_milters 和 non_smtpd_milters配置,追加如下:

smtpd_milters = unix:/spamass/spamass.sock, inet:localhost: non_smtpd_milters = unix:/spamass/spamass.sock, inet:localhost:

如果没有相关配置,直接用:

smtpd_milters = inet:localhost: non_smtpd_milters = inet:localhost:

3.5 执行如下命令

$ sudo mkdir /etc/opendkim $ sudo mkdir /etc/opendkim/keys

3.6 创建 /etc/opendkim/TrustedHosts , 前三行不要改动

127.0.0.1
localhost
192.168.0.1/ *.example.com

3.7 创建/etc/opendkim/KeyTable

mail._domainkey.example.com example.com:mail:/etc/opendkim/keys/example.com/mail.private

3.8 创建/etc/opendkim/SigningTable

*@example.com mail._domainkey.example.com

3.9 执行如下命令:

$ cd /etc/opendkim/keys $ sudo mkdir example.com

$ cd example.com $ sudo opendkim-genkey -s mail –d example.com

$ sudo chown opendkim:opendkim mail.private

3.10 接下来创建一个DNS TXT记录:

其中,名字为mail._domainkey

值要参考/etc/opendkim/keys/example.com/mail.txt, 格式为:

v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC5N3lnvvrYgPCRSoqn+awTpE+iGYcKBPpo8HHbcFfCIIV10Hwo4PhCoGZSaKVHOjDm4yefKXhQjM7iKzEPuBatE7O47hAx1CJpNuIdLxhILSbEmbMxJrJAG0HZVn8z6EAoOHZNaPHmK2h4UUrjOG8zA5BHfzJf7tGwI+K619fFUwIDAQAB

3.11重启服务,即可。

$ sudo service postfix restart $ sudo service opendkim restart

如有错误,请查看日志:/var/log/mail.err 和/var/log/mail.log

参考文档:

[1]“如何在Ubuntu 16.04上安装并配置Postfix作为只发送SMTP服务器” , http://blog.csdn.net/zstack_org/article/details/69525954

[2]“email基础篇 SPF设置说明”, https://tieba.baidu.com/p/3166555301?red_tag=1967972912

[3]“SSL对邮件加密的支持 Postfix+SSL配置”, http://shellyli.iteye.com/blog/1534717

Ubuntu16.04搭建Postfix作为SMTP服务器的更多相关文章

  1. Ubuntu16.04搭建OpenVPN

    Ubuntu16.04搭建OpenVPN 2018年12月27日 15:50:59 VinQin 阅读数:21042   简介 如果在一个非信任网络下比如旅社或者咖啡店的WiFi网络下,想要通过你的智 ...

  2. Ubuntu16.04搭建LAMP开发环境

    Ubuntu16.04搭建LAMP开发环境 虚拟机上安装好Ubuntu16.04后,是一台空白的Ubuntu.我的目的是搭建LAMP环境,顺便搭一个Python Django环境. 基本设置 1.配置 ...

  3. ubuntu16.04搭建ftp服务器

    因为习惯了vs进行开发,所以对于Linux的代码编辑开发都在vs里面进行,通常我们都是ssh远程登录到Linux,使用ftp或者sftp共享Linux目录里面的文件方便对文件的共享,这里介绍一下在ub ...

  4. Harbor 企业级私有仓库 Ubuntu16.04 搭建及使用

    一.Harbor简介 1.1.什么是Harbor 几个VMware中国的人搞了一个容器镜像仓库.Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器. 1.2.Harbor架 ...

  5. ubuntu16.04搭建个人简易DLP

    前言 最近一朋友让我帮忙搭建一台服务器,用做公司的服务器,但是该服务器需要满足一些安全要求,于是乎就有了下面的解决过程^_^ 需求 期望普通用户和管理员都能ssh登陆服务器,但禁止scp或者其他方式下 ...

  6. TestLink+Jenkins在Ubuntu16.04搭建集成测试环境

    序章 序1:TestLink和TestLink-API-Python-client 目前TestLink的最新版本是1.9.19 TestLink-API-Python-client支持的TestLi ...

  7. centos6.8 搭建postfix/dovecot邮件服务器

    postfix/dovecot邮件服务器 安装配置参考链接  http://www.cnblogs.com/jkklearn/p/7280045.html (domain 为自己域名 xxx.com) ...

  8. 【.NetCore学习】ubuntu16.04 搭建.net core mvc api 运行环境

    查看linux内核版本 uname -a 打印结果 python@ubuntu:~$ uname -a Linux ubuntu 4.4.0-31-generic #50-Ubuntu SMP Wed ...

  9. Ubuntu 16.04搭建php5.6 Web服务器环境

    Ubuntu 16.04默认安装php7.0环境,但是php7目前兼容性并不是很好,如果自行安装php5需要清除php7的已安装包,否则会报错. 移除默认及已安装的PHP包 sudo dpkg -l ...

随机推荐

  1. c/c++中int main(int argc,char *argv[])的具体含义

    int main(int argc,char * argv[ ]) argv为指针的指针 argc为整数 char **argv or: char *argv[ ] or: char argv[ ][ ...

  2. Oracle的decode、sign、trunc函数

    原文http://knowyouknowme.iteye.com/blog/574974 一.decode 在Oracle/PLSQL中,  decode 具有和 IF-THEN-ELSE 一样的功能 ...

  3. Internet Explorer 11:不要再叫我IE

    上周,Internet Explorer 11搭载Windows 8.1预览版而来,相信很多浏览迷也已经在使用中.Internet Explorer 11 Preview 改进了与 Web 标准.其他 ...

  4. Dll注入经典方法完整版

    总结一下基本的注入过程,分注入和卸载 注入Dll: 1,OpenProcess获得要注入进程的句柄 2,VirtualAllocEx在远程进程中开辟出一段内存,长度为strlen(dllname)+1 ...

  5. 如何用C#动态编译、执行代码

    在开始之前,先熟悉几个类及部分属性.方法:CSharpCodeProvider.ICodeCompiler.CompilerParameters.CompilerResults.Assembly. 一 ...

  6. 使用promise 和 generator来管理工作流

    根据p219的代码改编 示例代码如下 function oneStep(value){ return new Promise(function(resolve, reject){ resolve('o ...

  7. 使用lightProbe来模拟动态物体的照明shader

    VertexLit path中读取lightProbe烘焙信息: Shader "VertexLitProbe" { Properties { _MainTex ("Ba ...

  8. Jmeter笔记:响应断言详解

    转自:http://www.51testing.com/html/80/n-2430180.html 平时我们使用jmeter进行性能测试时,经常会用到断言.jmeter提供了很多种断言,本来想全都写 ...

  9. 安装Logtail(Linux系统)

    Logtail客户端是日志服务提供的日志采集客户端,请参考本文档,在Linux服务器上安装Logtail客户端. 支持的系统 支持如下版本的Linux x86-64(64位)服务器: Aliyun L ...

  10. 【SqlServer】SqlServer的常规操作

    创建一张新表,不负责任何数据(该表不会有原来表的主键.索引等等) select * into NewTable from OldTable where 1<>1; 创建一张新表,并且复制旧 ...