开始按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. Oracle11g服务详细介绍

    Oracle11g服务详细介绍及哪些服务是必须开启的? Oracle ORCL VSS Writer Service Oracle卷映射拷贝写入服务,VSS(Volume Shadow Copy Se ...

  2. eclipce连接数据库增删改查

    1.在mysql中新建一个名为course的数据库,并在其中新建一个course数据表,包含四个字段,id,name,teacher,classname如图(注意:将id设为自动递增,否则后面新增会出 ...

  3. 1.3.6、CDH 搭建Hadoop在安装之前(端口---DistCp使用的端口)

    DistCp使用的端口 列出的所有端口都是TCP. 在下表中,每个端口的“ 访问要求”列通常是“内部”或“外部”.在此上下文中,“内部”表示端口仅用于组件之间的通信; “外部”表示该端口可用于内部或外 ...

  4. native和webview切换

    native和webview 标签(空格分隔): native和webview 现在目前大部分的app都是native和webview混合,对应的native上的元素可以通过uiautomatorvi ...

  5. 八、AbstractFactory 抽象工厂模式

    设计原理: 代码清单: 抽象 Factory : public abstract class Factory { public static Factory getFactory(String cla ...

  6. openstack(Pike 版)集群部署(四)--- Nova 部署

    一.介绍 参照官网部署:https://docs.openstack.org/nova/pike/install/    继续上一博客进行部署:http://www.cnblogs.com/weiji ...

  7. suse glibcxx版本过高问题

    实际开发中发现,suse11虽然glibc版本很低,只有2.11.3,但是glibcxx版本很高,达到了3.4.19.这里我需要降低glibcxx版本.所谓glibcxx版本,即libstdc++.s ...

  8. NumPy 切片和索引

    NumPy 切片和索引 ndarray对象的内容可以通过索引或切片来访问和修改,与 Python 中 list 的切片操作一样. ndarray 数组可以基于 0 - n 的下标进行索引,切片对象可以 ...

  9. Codeforces Beta Round #31 (Div. 2, Codeforces format)

    Codeforces Beta Round #31 (Div. 2, Codeforces format) http://codeforces.com/contest/31 A #include< ...

  10. sourceforge

    sourceforge SourceForge.net,又称SF.net,是开源软件开发者进行开发管理的集中式场所. SourceForge.net由VA Software提供主机,并运行Source ...