Where are sendmail emails stored?

I am trying to build an autoresponder script for sendmail (no, I don't want to use a pre-built one yet), but I can't seem to find the location of received emails on my server. I have to specify that my configuration is not a default one.

I've looked in /root, there is no mail folder there. (I don't have any other user than root). I've looked in /var/mail/root, there are just some logs which are sent to me by mail, but not external mail that I receive from users.

I've checked /var/log/maillog, but there are no errors.

I'm out of ideas where to look. Could anyone help me?


Solution 1:

sendmail (a mail transport agent - MTA) stores mail in the place where it is configured to store mail. But an MTA only stores mail which it is currently queueing - delivery of mail to the location where it is accessible by a user is handled by the mail delivery agent (MDA). While sendmail (and other MTAs) can act as an MDA, it's very unusual for that to be the case.

Regardless, trying to access the mail files is not the right way to implement an autoresponder.

This should be done as a filter in the MTA (i.e. a milter) or in the MDA. The milter API is specifically designed for this - and there may already be tools available which would meet your requirement with no modification.

If your current MDA is procmail then in you're in luck - this provides a huge amount of flexibility (indeed its a programming language in its own right) for handling mail messages. Again there is lots of code on the internet which may meet your needs (AFAIK there is no central respository for procmail recipes - but try google).

Even the basic .forward mechanism can be used to implement this - but I'd advise against this - goingdown the procmail route you can fork the message so that delivery is not dependent upon/implemented by your script.

Solution 2:

If you have other than default directories configured, you should look at your /etc/mail/sendmail.cf to see what the paths are set to.

Not only does this vary betweeen OS distribution, but even the default directories between different versions of sendmail changed. In short, just for us to tell you the defaults, we need to know the OS version AND the sendmail version. Defaults are /var/spool/mail/$USERNAME for the mail drop, then if a user reads the mail with another application it is usually moved to $HOME/mbox.

Here is a list of common mail directories:

  • /var/mail/$USERNAME
  • /var/spool/mail/$USERNAME
  • $HOME/mbox
  • $HOME/mail
  • $HOME/Maildir

Solution 3:

It depends on how it's configured, but the usual place is /var/spool/mail, or some distros /var/mail. If it's in neither of those places, let us know, and we'll start digging!