修改后的日志to = 变成 [email protected] ->
这是sent日志
Nov 21 12:56:27 chrd-edm postfix/smtp[11762]: 208E0100735: [email protected] -> <[email protected]>, relay=mx3.qq.com[112.90.138.89]:25, delay=0.94, delays=0.09/0.01/0.51/0.33, dsn=2.0.0, status=sent (250 Ok: queued as )
Nov 21 12:56:27 chrd-edm postfix/qmgr[11527]: 208E0100735: removed
这是defer日志Nov 21 13:01:00 chrd-edm postfix/smtp[11788]: 9DA49100735: [email protected] -> <[email protected]>, relay=163mx01.mxmail.netease.com[220.181.12.62]:25, delay=3.4, delays=0.09/0.01/2.1/1.2, dsn=5.0.0, status=bounced (host 163mx01.mxmail.netease.com[220.181.12.62] said: 550 User not found: [email protected] (in reply to RCPT TO command))
修改方法:
global/recipient_list.h 24行增加了struct 的 char *letterInfo;成员;
本结构将变成
typedef struct RECIPIENT {
char *letterInfo;/* add by qidizi debug,rec letter info,letter db id ie. */
long offset; /* REC_TYPE_RCPT byte */
const char *dsn_orcpt; /* DSN original recipient */
int dsn_notify; /* DSN notify flags */
const char *orig_addr; /* null or original recipient */
const char *address; /* complete address */
union { /* Application specific. */
int status; /* SMTP client */
struct QMGR_QUEUE *queue; /* Queue manager */
const char *addr_type; /* DSN */
} u;
} RECIPIENT;
------------------------- ------------------
global/deliver_request.c 314行 增加,使用此方法复制,避免修改add方法而要修改其它文件代码.因为qmgr_message.c也用到add方法
while (rcpt_count-- > 0) {
if (attr_scan(stream, ATTR_FLAG_STRICT,
ATTR_TYPE_FUNC, rcpb_scan, (void *) rcpt_buf,
ATTR_TYPE_END) != 1) {
msg_warn("%s: error receiving recipient attributes", myname);
return (-1);
}
recipient_list_add(&request->rcpt_list, rcpt_buf->offset,
vstring_str(rcpt_buf->dsn_orcpt),
rcpt_buf->dsn_notify,
vstring_str(rcpt_buf->orig_addr),
vstring_str(rcpt_buf->address));
request->rcpt_list.info[request->rcpt_list.len - 1].letterInfo = mystrdup(request->sender); /* add by qidizi debug */
}
-------------
global/recipient_list.c
151行增加,因为其它地方还调用到,为了不改动其它地方,在这里初始化成空串,防止其它地方调用到,但是没有初始化,而后面log_adhoc.c用到会出现指针问题
/* recipient_list_add - add rcpt to list */
void recipient_list_add(RECIPIENT_LIST *list, long offset,
const char *dsn_orcpt, int dsn_notify,
const char *orig_rcpt, const char *rcpt)
{
int new_avail;
if (list->len >= list->avail) {
new_avail = list->avail * 2;
list->info = (RECIPIENT *)
myrealloc((char *) list->info, new_avail * sizeof(RECIPIENT));
list->avail = new_avail;
}
list->info[list->len].letterInfo = mystrdup(""); /* add by qidizi debug, */
list->info[list->len].orig_addr = mystrdup(orig_rcpt);
list->info[list->len].address = mystrdup(rcpt);
list->info[list->len].offset = offset;
list->info[list->len].dsn_orcpt = mystrdup(dsn_orcpt);
list->info[list->len].dsn_notify = dsn_notify;
if (list->variant == RCPT_LIST_INIT_STATUS)
list->info[list->len].u.status = 0;
else if (list->variant == RCPT_LIST_INIT_QUEUE)
list->info[list->len].u.queue = 0;
else if (list->variant == RCPT_LIST_INIT_ADDR)
list->info[list->len].u.addr_type = 0;
list->len++;
}
---------
global/log_adhoc.c 109行 修改成,增加一个输出参数recipient->letterInfo
/*
* Alas, we need an intermediate buffer for the pre-formatted result.
* There are several optional fields, and the delay fields are formatted
* in a manner that is not supported by vstring_sprintf().
*/
if (buf == 0)
buf = vstring_alloc(100);
/*
* First, critical information that identifies the nature of the
* transaction.
* edit by qidizi debug,out from
*/
vstring_sprintf(buf, "%s: from=<%s>, to=<%s>", id, recipient->letterInfo, recipient->address);
if (recipient->orig_addr && *recipient->orig_addr
&& strcasecmp(recipient->address, recipient->orig_addr) != 0)
vstring_sprintf_append(buf, ", orig_to=<%s>", recipient->orig_addr);
vstring_sprintf_append(buf, ", relay=%s", relay);
if (stats->reuse_count > 0)
vstring_sprintf_append(buf, ", conn_use=%d", stats->reuse_count + 1);
------------至此,修改结束---------
如果安装过postfix,需要在重新安装前结束它,下面是结束脚本
--------停止已安装的postfix的脚本,如果没安装过,不需要使用,如果路径不同需要修改,保存后,需要chmod 705 文件名 修改成可运行(本行不包含)-----------
#!/bin/sh
postfix stop
rm -rv /var/lib/postfix
rm -rv /var/spool/postfix
rm -rv /usr/lib/postfix
rm -v /usr/sbin/postfix
rm -v /usr/sbin/postalias
rm -v /usr/sbin/postcat
rm -v /usr/sbin/postconf
rm -v /usr/sbin/postsuper
rm -v /usr/sbin/postqueue
rm -v /usr/sbin/postmulti
rm -v /usr/sbin/postmap
rm -v /usr/sbin/postlog
rm -v /usr/sbin/postlock
rm -v /usr/sbin/postkick
rm -v /usr/sbin/postdrop
rm -v /var/log/mail*
/etc/init.d/rsyslog restart
----------脚本代码结束(本行不包含)-------------
---------清理上次编译命令,如果上回编译过才需要使用------
make tidy
-------编译,但不显示正常提示,如果提示有错误,需要检查代码(如果make命令不成功,需要安装make组件)----
make > /dev/null 2>&1
------------------------安装前需要配置好postfix的安装参数-----
1 把安装包中的conf文件夹中的所有文件复制到/etc/postfix里面,文件夹不存在,就创建;
2 修改main.cf成如下内容,安装时只需要install setting这节内容,其它内容是用于运行配置,可以按需要配置
---------postfix 专用发送不接收配置开始(配置文件中不要包含本行)-------------
#===========/etc/postfix/main.cf=============
#--------install setting------------
alias_maps = hash:/etc/aliases
#postfix shell
command_directory = /usr/sbin
#cf dir
config_directory = /etc/postfix
#daemon dir
daemon_directory = /usr/lib/postfix
#data dir
data_directory = /var/lib/postfix
#mail user
mail_owner = postfix
mailq_path = /usr/bin/mailq
manpage_directory = /usr/local/man
newaliases_path = /usr/bin/newaliases
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc
sample_directory = /usr/share/doc/postfix/examples
sendmail_path = /usr/sbin/sendmail
setgid_group = postdrop
#------------------------change default setting--------------
#bounce:Specify 0 when mail delivery should be tried only once
bounce_queue_lifetime = 0
#same domain concurrent,
default_destination_recipient_limit = 1
#Receive only circular letters
inet_interfaces = loopback-only
inet_protocols = ipv4
#First attempt to the same domain
initial_destination_concurrency = 1
#Do not allow local delivery
local_transport = error:local delivery is disabled
#Queue survival:Specify 0 when mail delivery should be tried only once.
maximal_queue_lifetime = 0
#
mydomain = myhrd.cn
#
myhostname = chrd-mail
#Sent with domain interval
smtp_destination_rate_delay = 30s
#smtp rules
smtpd_recipient_restrictions = reject_unknown_recipient_domain,permit_mynetworks,reject_unauth_destination
---------postfix 专用发送不接收配置结束(配置文件中不要包含本行)-------------
==========================================配置原则说明===============
配置中尽量只发,不收,拉大同域名,出错域名的发送频率.
让队列快速清除弹回信件
---------安装,在安装中出现的提示基本上可以直接回车一路过了,因为在/etc/postfix/main.cf中配置过这些参数了.--------
make install
------------启动postfix-----------
postfix start
---------查看postfix进程是否正常-------
ps ax |grep post
----查看postfix发送队列----
postqueue -p
------使用telnet 使用smtp通道测试发送--------
telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 chrd-mail ESMTP Postfix
-----------------------配置postfix日志--------因为postfix是使用系统日志组件生成日志,需要配置rsyslog
把所有的mail日志保存到一个文件中的配置
----------------/etc/rsyslog.d/50-default.conf(可能其它系统路径不同)--------------
mail.* /var/log/mail.log
--------------重启日志系统让配置生效,路径可能不同----------
/etc/init.d/rsyslog restart
成功就会提示运行情况,同时在/var/log目录下可以看到生成了mail.log
----------------------实时在shell中监测日志内容--------
1 关掉rsyslog服务, /etc/init.d/rsyslog stop
2 启动日志调试进程 rsyslogd -n ,这时,这个shell窗口将暂时成为监测窗口,不能输入了,
3 结束调试进程, 打开另一个shell窗口,得到rsyslogd的pid,方法一:ps ax |grep rsyslogd; 方法二cat /var/run/rsyslogd.pid;结束: kill -9 pid数字
-----增加自动启动/关闭----
/etc/init.d# ln -s /usr/sbin/postfix postfix
增加自动关闭
/etc/rc0.d# ln -s ../init.d/postfix K01postfix
K表示将般../init.d/postfix 发送参数stop,相当 ../init.d/postfix stop
01表示所处的顺序,如有时想让mysql启动处于89 apche 处于90,即谁先执行,好像最小是01,最大是99
后面postfix只用于区分.
对于rc*.d的数字有如下意义
# 0 - 停机(千万别把initdefault设置为0,否则系统永远无法启动)
# 1 - 单用户模式
# 2 - 多用户,没有 NFS
# 3 - 完全多用户模式(标准的运行级)
# 4 – 系统保留的
# 5 - X11 (x window)
# 6 - 重新启动 (千万不要把initdefault 设置为6,否则将一直在重启 )所以一般可以 0 stop 3 start
增加自动启动
/etc/rc3.d: ln -s ../init.d/postfix S99postfix
标签:sbin,postfix,smtp,list,usr,rm,mail,recipient
From: https://blog.51cto.com/u_252283/6235706