大网数据广告活动
服务器运维问答

linux: forward mail in mailbox

· 52CE 我爱测

Is it possible to forward mail out of a mailbox to another mailbox? I know about .forward, that's not what I want to do(seems like that's 100% of the answers out there). I already have mail in a mailbox I can see. I want to forwa…

问题原文

原帖链接 · ethos101 · CC BY-SA 3.0

Is it possible to forward mail out of a mailbox to another mailbox? I know about .forward, that's not what I want to do(seems like that's 100% of the answers out there). I already have mail in a mailbox I can see. I want to forward all of it to another mailbox that has a .forward that pipes into a script that files the emails into folders for records.

So you see I already have forwarding setup, I want to now forward mail out of one mailbox into another so it can forward its incoming emails to the script.

I'll confess, the reason being that the script broke for a while and now I have those mails queued up. I've fixed the script, I just need to re-forward the mail through the .forward.

Hopefully I've explained well enough. There doesn't seem to be a forward-mail option in the mail application.

已采纳解答

原帖链接 · AnFi onet.eu · CC BY-SA 3.0

You may use formail program to feed "one by one" messages in mailbox-file to program/script of your choice.

Below please find elaborate example of using formail -s ... to process user system mailboxfile. It is provided in man procmail and makes procmail process every message in the system mailbox.

#!/bin/sh

ORGMAIL=/var/mail/$LOGNAME

if cd $HOME &&
  test -s $ORGMAIL &&
  lockfile -r0 -l1024 .newmail.lock 2>/dev/null
then
  trap "rm -f .newmail.lock" 1 2 3 13 15
  umask 077
  lockfile -l1024 -ml
  cat $ORGMAIL >>.newmail &&
  cat /dev/null >$ORGMAIL
  lockfile -mu
  formail -s procmail <.newmail &&
  rm -f .newmail
  rm -f .newmail.lock
fi
exit 0

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-04-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。