postfix 如何设置邮件头翻译的功能
开始按http://semi-legitimate.com/blog/item/how-to-rewrite-outgoing-address-in-postfix 博客中的方法进行设置,是可以替换,但是webmail上面可替换。
下面引用该博客的
Sometimes I find myself configuring an internal Linux machine to be able to send emails for alerts or from a
particular application. Since this will not be a primary mail server, I just want to rewrite the outgoing
address to be something that make sense with the proper domain for the users. Here are the quick steps to accomplish this: vi /etc/postfix/main.cf Modify the "mydomain" variable to your email domain mydomain = example.com Make sure to uncomment the proper network interface. I'm usually lazy and just do all. inet_interfaces = all Now at the bottom of this file you need to specify the generic map file for rewriting the address. smtp_generic_maps = hash:/etc/postfix/generic Save and exit main.cf. Now we need to edit /etc/postfix/generic vi /etc/postfix/generic You need to specify the mapping of the original address to the one you want. Since in this case I just
want to rewrite everything I usually add the following two lines and it seems to catch everything. root@example.com no-reply@example.com
@example.com no-reply@example.com Save and exit the file. Now we need to create the postfix db. postmap /etc/postfix/generic This will create the /etc/postfix/generic.db hash file.
Now just restart postfix and test. /etc/init.d/postfix restart EDIT: umm..so I was doing this on an old version of Red Hat/Postfix 2.0 and my own directions
didn't work. (embarrassing...) Turns out you have to use a different file. Instead of using smtp_generic_maps,
use sender_canonical_maps like so: sender_canonical_maps = hash:/etc/postfix/canonical Then /etc/postfix/canonical is setup just like the generic file example above. Use the postmap /etc/postfix/canonical Restart postfix and test.
再次google. 找到http://itdept.blog.51cto.com/1034307/1104223
在此很感谢itdept,因为你的此细而帮助了我。我自认写不到你那么仔细。
开始我也一样,准备开始使用正则。来达到目的。但是最后没有最后了。
1.用header_checker检查头文件,用正则匹配替换发件人地址From
如将user01@test.com发件地址替换成user01@ct.com
Vim main.cf
添加如下开启头检查,使用的是pcre方式。
header_checks = pcre:/etc/postfix/my_header_checks
建立my_header_checks文件
/^From:(.*)[<]([\w\.\-]+)\@test\.com[>]/i REPLACEFrom:$1<$2@ct.com>
记得每次修改完my_header_checks文件要重新加载postfix否则出现正则是对的,而匹配出的地址格式显示是错误的
Service postfix reload
以上方法只配置了From:部分,而To:部分如何写正则,真的不好写。
再次启程,使用smtp_generic_maps,这个我操作的时间最久,一直以为配置是正常的,但是就是不可以,最终只有使用 sender_canonical_maps = hash:/etc/postfix/canonical 才可以。看上面的博客可以看到,会有些版本有问题,需要使用 canonical 的文件。
EDIT: umm..so I was doing this on an old version of Red Hat/Postfix 2.0 and my own directions
didn't work. (embarrassing...) Turns out you have to use a different file. Instead of using smtp_generic_maps,
use sender_canonical_maps like so:
2.第二种方法则是postfix的smtp_generic_maps参数设置。类似于sendmail的地址伪装功能,可以将本地网域的邮件地址改写成internet上合法的邮件
域名地址。smtp_generic_maps
只作用于外发的需要SMTP的邮件,本地域的内邮件收发,地址是不会修改的。smtp_generic_maps
如将user01@domain.local转换改写成user01@domain.com邮件网关网域地址
文件设置如下
配置postfix添加
Vim main.cf
smtp_generic_maps = hash:/etc/postfix/my_generic_maps vim my_generic_maps
user01@domain.local user01@domain.com
@localdomain.local @hisisp.example 建立文件后需要postmap生产hash数据文件
postmap /etc/postfix/my_generic_maps
service postfix reload 该参数会修改掉邮件header的路由、From:、To:相关邮件地址信息
它作用范围,只会修改掉需要发送出去到别台邮件服务器的邮件地址相关信息,local邮件不影响。
canonical_maps = hash:/etc/postfix/canonical
也可以分别为收件人和发件人地址分别指定不同的改写规范,这时参数sender_canonical_maps和recipient_canonical_maps的优先级比canonical_maps高。如:
sender_canonical_maps = hash:/etc/postfix/sender_canonical
recipient_canonical_maps = hash:/etc/postfix/recipient_canonical
看到itdept的测试,不得不说,哎,可惜没有早看到你的博客,我测试了许久,也看到了这个问题。最终在main.cf文件中添加
local_header_rewrite_clients = static:all
来处理了。
注意:基于以上测试时我发现,用webmail发送的邮件,对方收到的邮件显示地址为改写后的地址(改写成功),但 我用OUTLOOK2007发送的邮件对方收到的邮件显示地址
并没有被改写。查看header头文件路由Delivered-To:路由信息已被修改但是 From:与To:部分的地址没有被改。,
查阅postfix 官网有提到如下注意,而网上与postfix指南都没有这个说明,导致这个问题折腾了我很久。
NOTE: Postfix versions 2.2 and later rewrite message headers from remote SMTP clients only if the client matches the
local_header_rewrite_clients parameter, or if the remote_header_rewrite_domain configuration parameter specifies a
non-empty value. To get the behavior before Postfix 2.2, specify "local_header_rewrite_clients = static:all".
邮件地址改写作用范围是受local_header_rewrite_clients 设定控制的。默认只是改写
local_header_rewrite_clients (default: permit_inet_interfaces)
permit_inet_interfaces只作用于
Append the domain name in $myorigin or $mydomain when the client IP address matches $inet_interfaces. This is enabled by default.
我们可以自定义可以邮件地址改写的作用范围: local_header_rewrite_clients = permit_mynetworks, permit_sasl_authenticated permit_tls_clientcerts check_address_map hash:/etc/postfix/pop-before-smtp
我想任何符合canonical表的邮件无论谁发送的都改写,只需在main.cf添加上,就可以了。
local_header_rewrite_clients = static:all
最终简化的结果为:
邮件头翻译操作步骤
1./etc/postfix/main.cf 添加 smtp_generic_maps = hash:/etc/postfix/generic sender_canonical_maps = hash:/etc/postfix/canonical local_header_rewrite_clients = static:all 2.新建 /etc/postfix/generic 文件,建好复制一份为canonical内容格式如下 需要被替换的邮箱地址 目的邮箱地址 root@example.com no-reply@example.com 3.postmap /etc/postfix/generic 4. postmap /etc/postfix/canonical 5.最好重启下postfix的服务service umail_postfix restart
注意,有一弊端,此设置,不管发给那里都会被替换,包括自己发给自己的邮件头也会被替换。需要进一步改进配置。暂时没有研究出来。希望知道的兄弟给个提示。
postfix 如何设置邮件头翻译的功能的更多相关文章
- postfix 设置邮件头翻译,本域邮件不进行邮件头翻译,仅发送至外网的进行邮件头翻译?
postfix 设置邮件头翻译,本域邮件不进行邮件头翻译,仅发送至外网的进行邮件头翻译? 现在设置的 smtp_generic_maps = hash:/etc/postfix/generic sen ...
- zabbix3 设置邮件报警(五)
Zabbix邮件报警配置 一.安装sendmail或者postfix(安装一种即可) yum install sendmail #安装 service sendmail start #启动 chkco ...
- CentOS 6.x 下Postfix和dovecot邮件服务安装和基本配置
1 卸载sendmail [root@mail~]# pstree | grep sendmail [root@mail~]# service sendmail stop [root@mail~]# ...
- postfix 邮箱设置及常见错误
postfix 邮箱设置及常见错误 1.如果装了sendmail的话,先卸载了. yum remove sendmail 2.安装 Postfix yum install postfix 3.更改默认 ...
- 通过设置P3P头来实现跨域访问COOKIE
通过设置P3P头来实现跨域访问COOKIE 实际工作中,类似这样的要求很多,比如说,我们有两个域名,我们想实现在一个域名登录后,能自动完成另一个域名的登录,也就是PASSPORT的功能. 我只写一个大 ...
- 工程师技术(二):postfix基础邮件服务、postfix空客户端邮件服务、搭建mariadb数据库系统、配置一个数据库、使用数据库查询
一.postfix基础邮件服务 目标: 本例要求在虚拟机server0上配置 postfix 基础服务,具体要求如下: 1> 监听本机的所有接口 2> 将邮件域和邮件服务主机名都改为 ...
- 教你看懂邮件头信息<转载>
MIME对于邮件系统的扩展是巨大的,因为在MIME出现以前,信件内容如果要包括声音和动画,就必须把它变为ASCII码或把二进制的信息变成可以传送的编码标准,而接收方必须经过解码才可以获得声音和图画信息 ...
- intellj idea 如何设置类头注释和方法注释
intellj idea 如何设置类头注释和方法注释 intellj idea的强大之处就不多说了,相信每个用过它的人都会体会到,但是我们也会被他的复杂搞的晕头转向,尤其刚从ecl ...
- HttpServletResponse ServletResponse 返回响应 设置响应头设置响应正文体 重定向 常用方法 如何重定向 响应编码 响应乱码
HttpServletResponse 和 ServletResponse 都是接口 具体的类型对象是由Servlet容器传递过来 ServletResponse对象的功能分为以下四种: ...
随机推荐
- OpenCV之Vec3f
Vec3f表示的是3通道float类型的 Vect,就相当于3通道float类型的图像(这是其中一个具体化),解释可以从源代码中看出来. 下面给出一个具体的例子: Vec3f point = Vec3 ...
- vue iview tree checked改变 不渲染的问题
子级的状态 改为checked=false 需要把父的状态改为 false
- 游戏AI技术
[Unity3D人工智能编程精粹] 1.运动层.决策层.战略层. 运动层.决策层包含的算法是针对单个角色的,战略层是针对小队乃至更大规模群体的. 导航和寻路是运行层的主要任务. 决策层决定角色下一时间 ...
- Spring启动异常: cvc-elt.1: Cannot find the declaration of element 'beans'(转)
Spring启动异常: cvc-elt.1: Cannot find the declaration of element 'beans' 2008-09-07 22:41 今天把在线聊天室代码改了下 ...
- day11 闭包函数和装饰器
1.函数不是新知识点 主要是学习函数的用法 在面向对象编程中,一切皆对象,函数也不例外 具体的表现 1.函数可以引用 2.函数可以作为函数的参数 3.函数可以作为函数的返回值 4.可以被存储到容器类型 ...
- Appium 连手机失败Error: Android bootstrap socket crashed: Error: getaddrinfo ENOTFOUND localhost undefined:4724
问题:Appium执行,连接手机报下面的错误 Error: Android bootstrap socket crashed: Error: getaddrinfo ENOTFOUND localho ...
- oracle 存储过程模板
CREATE OR REPLACEPROCEDURE PROCE_NAME(V_IN varchar2, V_OUT out varchar2) ASBEGIN --... commit; V_O ...
- OpenSessionInViewFilter 的配置及作用(原文地址: http://blog.csdn.net/sunsea08/article/details/4545186)
spring为我们解决hibernate的Session的关闭与开启问题. Hibernate 允许对关联对象.属性进行延迟加载,但是必须保证延迟加载的操作限于同一个 Hibernate Sessio ...
- centos磁盘满了,查找大文件并清理
今天发现vps敲入crontab -e 居然提示 “Disk quota exceeded” 无法编辑.于是"df -h"查了查发现系统磁盘空间使用100%了.最后定位到是/var ...
- Nginx 功能
本文只针对Nginx在不加载第三方模块的情况能处理哪些事情,由于第三方模块太多所以也介绍不完,当然本文本身也可能介绍的不完整,毕竟只是我个人使用过和了解到过得,欢迎留言交流. Nginx能做什么 ...