procmail
[Top] [All Lists]

Re: Bouncing Mail ......

1995-12-01 20:48:13
  Hello, 

  I am attempting to use procmail to restrict certain individuals
  from sending me email. I have been succussful. However, I would
  like to have a message bounce back to those users. I am not quite
  sure how to go about doing this. I have looked over the man page
  and as I am not a system administrator have not been able to figure
  out how to get this 2nd part working. Can you send me a tip ? Thanks,
  or the name of further places to look would be most excellent. 

Rose, try something like this (it is untested, but should show you how):

Create the file (given below) as "reject.rc" in your default MAILDIR
directory. 

Then, your ~/.procmailrc, add the following line:

    INCLUDERC=reject.rc

The "reject.rc" file below depends upon "multigram", which is part of
procmail, but compiled only when installing SmartList.  You may have to
pretend to install SmartList if only to get the Makefiles to create
multigram. 

As an alternative to multigram, you can use grep as in the following
condition:

    FROM=`formail -rtzXTo:`     # get how it's from

    :0
    * ? grep -s "$FROM" $REJECTFILE
    { ...

Here's the reject.rc file (using multigram):

reject.rc:
============================= cut here ===================================
    # File to check for mail from a list of addresses from which to reject mail

    # if you touch reject.rc.log, you'll get copious logging info
    # remove reject.rc.log after you're sure it works.
    :0
    * ? test -f reject.rc.log
    { LOGFILE=reject.rc.log LOGABSTRACT=all VERBOSE=yes }

    REJECTFILE=reject-list      # file containing addresses to reject
                                # and bounce back mail to
    FORMAIL=formail             # /usr/local/bin/formail
    MULTIGRAM=multigram         # ~lists/.bin/multigram
    
    # if the sender is in the reject file, then bounce back a message
    :0 :$REJECTFILE.lock
    * $ ! ^X-Loop: *$LOGNAME(_at_)$HOST
    * ? $FORMAIL -rtzXTo: | $MULTIGRAM -b1 -l20000 -i $REJECTFILE
    {
        DELIVERED=yes           # tell sendmail that the mail was delivered
        COMSAT=no               # but be quiet about it

        # First make a copy of the entire mail
        REJECTMAIL=reject.mail
        LOCKFILE=$REJECTMAIL.lock
        :0c 
        $REJECTMAIL

        # Replace the mail with a reply
        FROMSIG="$LOGNAME's Mailer-Daemon <$USER>"
        SUBJECT="Your mail has been rejected"

        # (Note: do not use -k here; "h" recipes include the blank
        # line in the headers, and formail -r generates a blank line
        # also.  If you use '-k', then the original blank line will 
        # be kept, and the additional will be added, resulting
        # in two blank lines).

        :0 fhw
        | $FORMAIL -rtI"From:       $FROMSIG"                                   
\
                     -I"Subject:    $SUBJ"                                      
\
                     -I"X-Loop:     $LOGNAME(_at_)$HOST"                        
        \
                     -I"Precedence: junk"                                       
\
          ; echo "Your mail is being returned to you, unread, because your"     
\
          ; echo email address is on my \"reject\" list."                       
\
          ; echo ""                                                             
\
          ; echo "Your original mail follows:"                                  
\
          ; echo "-----------------------------------------------------"        
\
          ; cat $REJECTMAIL

        # release the lock file now
        LOCKFILE

        # Finally, deliver it
        :0 w
        ! -oi -t

        HOST=end_of_processing          # just in case sendmail failed
    }

<Prev in Thread] Current Thread [Next in Thread>
  • Re: Bouncing Mail ......, Alan Stebbens <=