开始按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邮件不影响。
3.还可以使用邮件地址规范改写参数canonical_maps实现邮件地址改写:

Canonical_maps的作用区域local与smtp所有邮件,可以用来规范邮件地址,

Firstname.Lastname 风格的地址以及清除无效的域。

缺省postfix是不进行规范地址改写的,你可以通过指定canonical_maps参数的值来使其生效。如:
  canonical_maps = hash:/etc/postfix/canonical 

 

Vim canonical

wyjos@test.com     jos.wang@test.com

@testmail.com @test.com

 

地址改写可以基于单个邮件地址,也可以基于整个域设定。
也可以分别为收件人和发件人地址分别指定不同的改写规范,这时参数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 如何设置邮件头翻译的功能的更多相关文章

  1. postfix 设置邮件头翻译,本域邮件不进行邮件头翻译,仅发送至外网的进行邮件头翻译?

    postfix 设置邮件头翻译,本域邮件不进行邮件头翻译,仅发送至外网的进行邮件头翻译? 现在设置的 smtp_generic_maps = hash:/etc/postfix/generic sen ...

  2. zabbix3 设置邮件报警(五)

    Zabbix邮件报警配置 一.安装sendmail或者postfix(安装一种即可) yum install sendmail #安装 service sendmail start #启动 chkco ...

  3. CentOS 6.x 下Postfix和dovecot邮件服务安装和基本配置

    1 卸载sendmail [root@mail~]# pstree | grep sendmail [root@mail~]# service sendmail stop [root@mail~]# ...

  4. postfix 邮箱设置及常见错误

    postfix 邮箱设置及常见错误 1.如果装了sendmail的话,先卸载了. yum remove sendmail 2.安装 Postfix yum install postfix 3.更改默认 ...

  5. 通过设置P3P头来实现跨域访问COOKIE

    通过设置P3P头来实现跨域访问COOKIE 实际工作中,类似这样的要求很多,比如说,我们有两个域名,我们想实现在一个域名登录后,能自动完成另一个域名的登录,也就是PASSPORT的功能. 我只写一个大 ...

  6. 工程师技术(二):postfix基础邮件服务、postfix空客户端邮件服务、搭建mariadb数据库系统、配置一个数据库、使用数据库查询

    一.postfix基础邮件服务 目标: 本例要求在虚拟机server0上配置 postfix 基础服务,具体要求如下: 1> 监听本机的所有接口    2> 将邮件域和邮件服务主机名都改为 ...

  7. 教你看懂邮件头信息<转载>

    MIME对于邮件系统的扩展是巨大的,因为在MIME出现以前,信件内容如果要包括声音和动画,就必须把它变为ASCII码或把二进制的信息变成可以传送的编码标准,而接收方必须经过解码才可以获得声音和图画信息 ...

  8. intellj idea 如何设置类头注释和方法注释

    intellj idea 如何设置类头注释和方法注释           intellj idea的强大之处就不多说了,相信每个用过它的人都会体会到,但是我们也会被他的复杂搞的晕头转向,尤其刚从ecl ...

  9. HttpServletResponse ServletResponse 返回响应 设置响应头设置响应正文体 重定向 常用方法 如何重定向 响应编码 响应乱码

    HttpServletResponse  和 ServletResponse  都是接口 具体的类型对象是由Servlet容器传递过来   ServletResponse对象的功能分为以下四种:   ...

随机推荐

  1. linux下arm汇编的常用指令解析

    1. ldr 和 str : (1) ldr 作为指令,叫做寄存器加载指令.将内存中的值加载到寄存器中. (2) ldr 作为伪指令,实现一个32位常数或地址值加载到寄存器中.后面加载的常量或地址值标 ...

  2. JS----addEventListener()

    addEventListener() 用于向指定元素添加事件. 可以向一个元素添加多次事件或者多次不同事件,后面的事件是不会覆盖前面的. 语法: element.addEventListener(ev ...

  3. js循环对象,(多层数组)

    javaScript遍历对象.数组总结   在日常工作过程中,我们对于javaScript遍历对象.数组的操作是十分的频繁的,今天抽空把经常用到的方法小结一下,方便今后参考使用!     javaSc ...

  4. idea 修改 使用的git账号

    打开控制面板-->用户账户-->凭证管理器 如下图点击进入,删除原有的账号 当在idea中再提交或下载代码时,就会弹出如下提示框: 重新输入你自己的账号就可以了.

  5. 1.4、CDH 搭建Hadoop在安装之前(推荐的群集主机和角色分配)

    推荐的群集主机和角色分配 要点:本主题描述了Cloudera Manager管理的CDH群集的建议角色分配.您为部署选择的实际分配可能会有所不同,具体取决于工作负载的类型和数量,群集中部署的服务,硬件 ...

  6. Java中递归的优缺点,Java写一个递归遍历目录下面的所有文件包括子文件夹里边的文件。

    题目: 遍历出aaa文件夹下的文件 首先分析思路: 1.首先判断这个文件夹是否为文件,通过isFile()函数可以判断是否为文件. 2.然后通过isDirectory判断是否为目录. 3.如果是目录就 ...

  7. Compute Shader

    [Compute Shader] 1.Similar to regular shaders, compute shaders are Asset files in your project, with ...

  8. java中几个happens-before规则

    1. 程序顺序规则:一个线程中的每个操作,happens-before 该线程中的任意后续操作. 2.监视器锁规则:对一个锁的解锁, happens-before 于随后对这个锁的加锁操作 3.vol ...

  9. sqlserver 数据库迁移

    参考 https://blog.csdn.net/wuzhanwen/article/details/77449229 一.连接本地数据库引擎 新建一个数据库,如:rbrbsoft 二.连接远程数据库 ...

  10. 贪吃蛇snake Java实现(二)

    package cn.tcc.snake.antition; import java.awt.Color;import java.awt.Graphics;import java.awt.Point; ...