linux 解析邮件,linux – 使用mailx和bash脚本解析邮件的正文

如果这是通过类似sendmail的MTA传递到本地用户帐户的邮件,那么您可以使用procmail在发送邮件时对其进行解析.

在我使用的系统上,sendmail会检查〜/ .forward文件,所以我在~username / .forward中有这个

# pipe incoming mail to procmail

# ref: http://www.panix.com/~elflord/unix/procmail.html

# ref: http://porkmail.org/era/procmail/mini-faq.html#forward

"|IFS=' ' && p=/usr/local/bin/procmail && test -x $p && exec $p -f- || exit 75 #username"

然后,~username / .procmailrc包含:

# procmail tutorial: http://tldp.org/LDP/LG/issue14/procmail.html

PATH=/usr/local/bin:/bin:/usr/bin

MAILDIR=$HOME/Mail

DEFAULT=$HOME/Mail/inbox

LOGFILE=$HOME/procmail.`date +%Y-%m`.log

SHELL=/usr/bin/ksh

MY_XLOOP='X-Loop: username@hostname.subdomain.example.com'

MY_RECIPIENT='mailing.list@example.com'

#############################################################################

# if the email comes from the client with a specific Subject,

# send a copy of the message to the processing script, and

# carry on with the next recipe

:0c

* ^From:.*@clientdomain\.invalid

* ^Subject:.*Account.*(Request|Access|Approval)

| $HOME/bin/process_account_request_email.pl | \

mailx -s "Account request results" $MY_RECIPIENT

#############################################################################

# forward all mail to mailing list

:0

* ! ^$MY_XLOOP

{

# add a header

# 'f' = filter: pass message to program and continue processing results

# 'h' = pass message headers to program

# 'w' = wait for program to return

:0fhw

| formail -A "$MY_XLOOP"

# then forward the message

# 'c' = send a copy to recipient and continue processing

:0c

! $MY_RECIPIENT

}

# if we get here, then the message has an X-Loop header.

# let it fall into $DEFAULT

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值