Sendmail: A practical method to limit the user's mailbox size

Source: Internet
Author: User
Sendmail is a practical method to limit the user's mailbox size-Linux Enterprise Application-Linux server application information. The following is a detailed description. Currently, Sendmail is widely used in Linux/Unix as the mail server installed by default. However, Sendmail itself does not have the function of limiting the user's mailbox size. Therefore, if some users do not receive or set to retain the mail copy for a long time, their emails will accumulate on the server, as a result, the mailbox is getting bigger and bigger, occupying a lot of hard disk space. Many network administrators have a lot of opinions on this. A simple and practical method is introduced here. Through this method, we can easily and flexibly set the user's mailbox size.
  
   I. Basic Ideas
  
---- First set a threshold value for the size of a user's mailbox, and then regularly start a process to check the size of each user's mailbox file, temporarily write all mailbox file names that exceed this limit into a specific file; then read the file and write it into the blacklist_recipients of Sendmail, therefore, the email server rejects the user's new email until the mailbox size is smaller than the set threshold value at the next check.
  
   Ii. Runtime Environment
  
---- We use the Solaris 2.7 operating system as an example to describe other Unix (or Linux) systems.
  
---- This article takes Sendmail 8.11.3 as an example, if you do not have this version of Sendmail running software, you can download to the http://freesoft.cei.gov.cn or http://www.sendmail.org site.

   Iii. Specific operations
  
---- 1. Download and compile
---- Compile the Sendmail package after it has been downloaded to the current directory. The procedure is as follows.
---- $ Gzip-dc sendmail.8.11.3.tar.gz | tar-xf-(Gzip is a compressed/decompressed tool, which is equivalent to WinZip on Windows platform and can be easily found and downloaded online)
---- $ Cd sendmail-8.11.3/sendmail
---- $./Build
---- (Compile Sendmail)
  
---- 2. Install
---- #./Build install
---- (Installed as a Super User)
  
---- 3. Generate the configuration file
---- # Cd ../cf/domain
---- # Vi generic. m4
---- Add the following two lines at the end of the file.
---- FEATURE ('Access _ db', 'dbm/etc/mail/access') dnl
---- FEATURE ('blacklist _ recipients ') dnl
---- Then, enter the following content.
---- # Cd ../cf
---- # M4 ../m4/cf. m4./generic-solaris2.mc>./sendmail. cf
---- # Cp./sendmail. cf/etc/mail/
  
---- 4. Generate the access file and the parameter file of the email server name
---- # Cd/etc/mail
---- # Makemap dbm access </dev/null
---- # Vi local-host-names
---- (This file is a text file whose content is the domain name and alias of the local email server. Separate them by carriage return. For more information, see the Readme file)
  
---- 5. Start Sendmail
---- #/Usr/lib/sendmail-bd-q30m
  
---- 6. Compile a program that limits the mailbox size
---- Use the sh command to compile a program that limits the mailbox size, and then use the crontab function of the operating system to set the execution frequency. The content is as follows.
---- # Vi/etc/mail/limit_mailbox.sh
---- (For details, see the appendix)
---- # Chmod u + x/etc/mail/limit_mailbox.sh
---- # Crontab-e
  
---- Then, we can enter the following content.
  
---- 0 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ***/etc/mail/limit_mailbox.sh 10
  
---- It indicates to every day ~ Run the sh command at every one hour to check the mailbox size. You can also make adjustments based on the actual situation. "10" indicates that the mailbox size threshold is 10 MB.

   Iv. source code of the appendix limit_mailbox.sh
  
----#! /Usr/bin/ksh
---- # Search the mailbox larger than MAXSIZE, then set this mailbox full and reject new mails
  
Error (){
Echo "$1"
Exit 1
}
BIN =/usr/bin
MAIL =/etc/mail
# Directory of the Sendmail parameter file
MAILDIR =/var/mail
# Directory for storing mailbox files
ACCESS = access. db
# Used to temporarily store the mailbox name that exceeds the threshold
SUBACCESS = access. sub
# Used to store additional Receiving and forwarding restrictions
If [$ #-lt 1]; then
Error "Must set the MAX mailbox size with the command! "
Fi
If [$1-le 0]; then
Error "Mailbox Size <0, Failed"
Fi
(MAXSIZE = $1*1024*1024 ))
If [-f $ MAIL/$ SUBACCESS]; then
$ BIN/cat $ MAIL/$ SUBACCESS> $ MAIL/$ ACCESS''
Error "piping $ MAIL/$ SUBACCESS into $ MAIL/$ ACCESS, Failed"
Else
> $ MAIL/$ ACCESS ''error "clearing $ MAIL/$ ACCESS, Failed"
Fi
Cd $ MAILDIR ''error "entering $ MAILDIR Failed"
For box in '$ BIN/find.
! -User root-size + "$ MAXSIZE" c-type f-print '; do
Case $ box in
. |... |./. *. Pop)
;;
*)
Mailuser =$ {box #./}
Echo "To: $ mailuser @
ERROR: 550 $ mailuser's Mailbox is full "> $ MAIL/$ ACCESS
;;
Esac
Done
Cd $ MAIL | error "entering $ MAIL Failed"
/Usr/sbin/makemap dbm access
<./$ ACCESS | error "makemaping access Failed"
Exit 0'
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.