mail-deny -- block email from specific email-addresses or servers.
mail-deny (reads from STDIN)
mail-deny provides a simple way to block all email received from a specific
email address or server IP.
The mail-deny was created to help get rid of annoying email from unwanted
people or servers. mail-deny looks thru a user defined list of email
addresses or IP addresses and if the message is from an unwanted source the
header: 'X-mail-deny: YES' is appended to the headers.
mail-deny does not accept any command line options. It it reads from standard
input and then dumps the message back to standard out. With an extra header
if needed.
Script Configuration
The mail-deny requires the Perl module Net::SMTP and procmail need to be properly setup for the script to
work.
There is very little script-based configuration. The following variables
can be configured:
$enableLog
Found right after the usage comments in the main portion of the program.
This variable enables/disables logging for all users that use the script.
$server
Found in the sendResponse sub program. This variable specifies which SMTP
server to send responses thru. By default it is defined as "localhost".
$domain
Found in the sendResponse sub program. This variable specifies the domain
name that the response is going to be sent from. By default it is defined
as "localdomain".
$mailTo
Found in the sendResponse sub program. This variable specifies the email
address that the response should be sent to. It is set to $_[0] (the
email address from the ~/.mail-deny/blockaddr file). This should not be
changed it is used to find the file in ~/.mail-deny/ that contains the
message.
$mailFrom
Found in the sendResponse sub program. This variable specifies the email
address that the response is from. By default this is defined as
"postmaster\@$domain";
$subject
Found in the sendResponse sub program. This variable specifies the
subject of the email response. By default this is defined as "Message to
$username\@$domain not delivered".
User Configuration
This documentation is written assuming you are an administrator setting
up a user's account.
- procmail setup
The following lines need to be added to user's ~/.procmailrc
put them BEFORE any other filtering or spam detection.
# Used for mail-deny
:0fw
| /usr/local/bin/mail-deny
:0:
* ^X-mail-deny: YES
$HOME/mail/denied
# End of mail-deny
The $HOME/mail/denied could be replaced with /dev/null. Also make sure
that the path to mail-deny is correct.
You will also need to make sure that the user's email is configured to
use procmail.
- initialize user configuration
mail-deny relies on 2 configuration files and a log file to work
properly. Each time it is run mail-deny will create the following
3 files (and directory) if needed:
~/.mail-deny
~/.mail-deny/blockip
~/.mail-deny/blockaddr
~/.mail-deny/log
Before customizing the user's configuration you can either send or
wait for an email to show up - to create these files or run the
following command from the user's account:
echo "To: $(id -un)@localhost" | mail-deny
All of the configuration files should be modifiable by the user - so
that they can expand the configuration if later deemed necessary.
- customize user configuration
The following are the files and a description of their function and
format that each user can configure for use with mail-deny.
- ~/.mail-deny/log
This file contains the logs for all email
processed. This only has information if
$enableLog is set in this script.
- ~/.mail-deny/blockip
This file is used to block email received from a
specific IP address. Careful with this if the IP
is near right after a line beginning with "Received"
the message will be blocked. One IP per line.
- ~/.mail-deny/blockaddr
This file is used to block email received from a
specific email address. One email per line.
Individual email responses
To send a response to an email a user is blocking create a file in
~/.mail-deny/ with the same name as the email address that is being
blocked.
For example if you want to send a message to foo@somewhere.com
create the file ~/.mail-deny/foo@somewhere.com With
the body of the email message that will be sent to the person.
NOTES:
** Emails are sent from postmaster@$domain - make sure the messages
are appropriate.
** The message in the file will NOT be sent unless the email
address of the same name is in ~/.mail-deny/blockaddr.
If you find a bug please let me know email me at
thompson@cns.uni.edu.
Copyright (C) 2003 Aaron Thompson
thompson@cns.uni.edu
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA. or visit
http://www.gnu.org/copyleft/gpl.html
Click here to view the source code online
Click here to download the script