MBF Knowledge Base

How do I delete email messages from a user's inbox on a Sendmail server?

The usual configuration is that sendmail puts mail to a user in /var/spool/mail/[username]. That file is just all the messages for the user concatenated together. (Each message starts with a line that starts "From ".)

You can tell for sure by looking at /etc/sendmail.cf. Look for a line starting "Mlocal". That describes how local e-mail is to be delivered. The "P=" part of the line tells what program does the work.

You can simply move the /var/spool/mail file to another directory in the / partition -- that's safe because mv within a filesystem is atomic at the kernel level. Then you can edit the file however you want. It's a bit more difficult putting the edited file back, because you might do it at the same moment sendmail is delivering another message. The safest way is to stop sendmail, then concatenate the messages you want to retain onto /var/spool/mail/[user], or if it doesn't exist, just move it back. Then restart sendmail.