postfix中如何获得一个邮件的信封信息(envelop header)
有些时候,我们需要邮件的信封信息(envelop header),(一个邮件的信体信息很容易获得,这里不叙述)
下面简单的说说怎么通过postfix的pipe来获得一个邮件的信头信息
大概实现过程如下:
设置content_filter,让postfix把邮件送到content_filter所指向的filter程序,这个filter程序由postfix
的pipe来调用,pipe调用这个filter程序时候,可以把信封信息(mail from 和rcpt to 信息)传递给filter
程序
做法:
(1) filter程序的编写(这里使用shell)这个程序是:/tmp/myfilter.sh
内容如下
#!/bin/bash
cat > /tmp/messges_infor_txt #这句的作用就是把邮件的信体内容写到/tmp/messges_infor_txt文件中
echo "$@" > /tmp/envelop_infor_txt
#这句的作用就是把邮件的“信封内容”写到/tmp/envelop_infor_txt文件中
然后分别建立2个文件
touch /tmp/messges_infor_txt
touch /tmp/envelop_infor_txt
touch /tmp/messges_infor_txt
touch /tmp/envelop_infor_txt
设置相关的权限
chmod 777 /tmp/myfilter.sh
chmod 777 /tmp/messges_infor_txt
chmod 777 /tmp/envelop_infor_txt
(这里为了演示实现filter功能,所以设置为“world-writable”
大家设置的时候,请设置好限制,不要world-writable)
chmod 777 /tmp/myfilter.sh
chmod 777 /tmp/messges_infor_txt
chmod 777 /tmp/envelop_infor_txt
(这里为了演示实现filter功能,所以设置为“world-writable”
大家设置的时候,请设置好限制,不要world-writable)
(2)设置content_filter
在/etc/postfix/main.cf中设置
在/etc/postfix/main.cf中设置
content_filter = myfilter
(3)设置master.cf
在/etc/postfix/master.cf中加入:
myfilter unix - n n - - pipe
flags=Rq user=filter argv=/tmp/myfilter.sh ${sender} -- ${recipient}
在/etc/postfix/master.cf中加入:
myfilter unix - n n - - pipe
flags=Rq user=filter argv=/tmp/myfilter.sh ${sender} -- ${recipient}
(4)重载
/etc/init.d/postfix reload