首页 > 其他分享 >修改postfix/手工编译/安装让smtp日志包含mail from 信息

修改postfix/手工编译/安装让smtp日志包含mail from 信息

时间:2023-04-28 23:13:51浏览次数:41  
标签:sbin postfix smtp list usr rm mail recipient


修改后的日志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

相关文章

  • 接单日记(二)SMTP发送邮件
    目录接单日记(二)SMTP发送邮件一、实验目的二、实验内容三、程序及结果1、运行程序2、运行结果接单日记(二)SMTP发送邮件此为一个实验报告,故遵守实验报告的格式。一、实验目的熟悉SMTP发送邮件的原理使用SMTP实现自动化发送邮件的功能熟练在实际场景中使用装饰器,提高代码......
  • As a restaurant owner, write a professional email to the supplier to get these p
    Asarestaurantowner,writeaprofessionalemailtothesuppliertogettheseproductseveryweek:Wine(x10)Eggs(x24)Bread(x12)DearSupplier,Ihopethismessagefindsyouwell.Mynameis[YourName],andIamwritingonbehalfofmyrestaurant......
  • 修改Git全部Commit提交记录的用户名Name和邮箱Email
    当我们换邮箱了,想把已经提交过的commit的邮箱和用户名改成新的时候。先把本地配置成新的gitconfiguser.name'丁少华'gitconfiguser.email'新邮箱@xx.com'这时候就可以用下面的脚本代码了在项目根目录下创建email.sh写入下面这段代码#!/bin/shgitfilter-branch......
  • 首次发刊!Coremail管理员社区2023年Q1季刊发布
    4月21日,Coremail安全邮件城市沙龙在北京正式开展,此次沙龙活动的主题为“践行教育信创,护航邮件安全”。广东盈世计算机科技有限公司服务副总裁、ICANNUA大使吴秀诚在活动上正式发布《Coremail管理员社区2023年Q1季刊》。Coremail管理员社区Coremail管理社区属于云服务板块之一,由Cor......
  • email用法
    importsmtplibfromemail.mime.textimportMIMETextfromemail.mime.multipartimportMIMEMultipartfromemail.mime.imageimportMIMEImage#设置发件人和收件人sender='[email protected]'password='password'receiver='[email protected]'......
  • 邮箱伪造之搭建匿名SMTP服务器
      电子邮件欺骗(emailspoofing)的根本原因是SMTP协议是不需要身份验证的,攻击者可以利用这个特性伪造电子邮件头,从任意电子邮件地址发送任何人,导致信息看起来来源于某个人或某个地方,而实际却不是真实的源地址。   如果要实现邮箱伪造发件人地址,首先,我们需要一个可以用来发送......
  • node.js使用Nodemailer发送邮件
    引言--常常看到一些网站有邮箱获取验证码验证注册或者修改密码等,今天也来了解一下在nodejs+express怎么发送电子邮件。使用模块Nodemailer。这里以qq邮箱举例子。安装模块--npminstallNodemailer--save创建一个SMTP客户端配置--//引入模块nodemailerconstnodemai......
  • 喜报!Coremail连续10次入选《中国网络安全行业全景图》
    近日,国内权威媒体安全牛第十版《中国网络安全行业全景图》(以下简称“全景图”)正式发布。全景图共收录456家国内网络安全企业和相关机构,共分为15个一级安全分类,107个二级细分领域。Coremail凭借自身卓越的技术实力,突出的市场表现,完善的服务能力,已经连续十次入选“邮件安全”领域。邮......
  • 计算机网络基础——06 Email 服务器的配置和应用
    6.1 实验目的1.了解电子邮件的工作原理和常见的邮件服务器软件2.掌握电子邮件服务器软件 CMailServer 的安装和配置3.掌握使用浏览器和电子邮件客户端软件来收发电子邮件6.2 实验相关知识6.2.1 电子邮件的相关知识电子邮件的一般处理流程与传统邮件有相似之处:(1)当用户在计......
  • Please enter your authorization code to login. More information in http://servic
    1、问题出现背景集简云配置出现如下错误需要重新授权{"Code":2002,"Msg":"Failed","Data":{"error":"(535,b'LoginFail.Pleaseenteryourauthorizationcodetologin.Moreinformationinhttp://ser......