Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Feb 1999 10:33:56 -0500 (EST)
From:      Zach Smith <zach@bane.mi.org>
To:        kok <cckok00@stlinux.ouhk.edu.hk>
Cc:        FreeBSD Questions <questions@FreeBSD.ORG>
Subject:   Re: mail setting
Message-ID:  <Pine.LNX.3.96.990216102549.8952A-100000@bane.mi.org>
In-Reply-To: <36C98266.120973D6@stlinux.ouhk.edu.hk>

next in thread | previous in thread | raw e-mail | index | archive | help
here is an example of how you could do this with a simple mail filer
script and a .forward file.  This way, you don't need to rely on system
files or alias db's.  Please note, I wrote this in 5 mins and only tested
it about 5 times.  It should work for very simple messages but it is meant
to be an example of how you could do this, not necessarily the "way" to
do this.

Here is the script: mf.pl
---BEGIN SCRIPT---

#!/usr/local/bin/perl

  # file where your mail is stored.  usually something like
/var/spool/mail/USER
$mailfile="/var/spool/zach";
  # where you want the mail to go
$forwardaddress="zsmith1\@ford.com";

  # because this is going to be invoked via a pipe, we can just read STDIN
:)
while(<>) {
          #push everyline read into the @mail list
        push(@mail,$_);
}

  # open you system mail file...$mailfile
open(MAIL,">>$mailfile") || die("Coulnd not open $mailfile: $!\n");
  # print the e-mail message stored in @mail to the $mailfile
print MAIL @mail;
  # close the mail file
close(MAIL);

  # open a pipe to mail to send the message to the other account
open(ALTMAIL,"|mail $forwardaddress") || die("Could not open mail pipe:
$!\n");
  # print the message stored in @mail the pipe
print ALTMAIL @mail;
  # close the pipe
close(ALTMAIL);

---END SCRIPT---

Make sure this is executable because it will need to be executed.
Next, place this line in your .forward file:

| /PATH_TO_THE_SCRIPT/mf.pl

Where "PATH_TO_THE_SCRIPT" is where you put mf.pl

Again, please make sure you test this a lot and make any modifications
you need to fit your setup.  Good luck :) 

     Zach Smith
+-------------------+
|     UNIX Nerd     |
|         &         |
| Professional Geek |
+-------------------+
   zach@bane.mi.org

On Tue, 16 Feb 1999, kok wrote:

> Hello
> 
> i would like to know how to make mail setting:
> 
> forward mail to althernative mail account but keep mail to original
> account.
> 
> i know file .forward which can only forward to althernate mail account
> but couldn't keep mail to original account!
> 
> Thank you for your help
> 
> kok
> 
> 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message
> 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.3.96.990216102549.8952A-100000>