Our company has a server (VPS) which runs qmail. I have a number of IMAP mailboxes under our domain on this server and I want to find out how many emails are sent from our domain over a certain period (i.e. one month). Is there any way of doing this?
I would go for
grep -c "delivery [0-9]*: success" /path/to/your/logfile.log.
This will work fine on its own if your log files are rotated monthly. You may need to include more log files if they are rotated daily and if they don't match any time-based schedule then you may have to grep for the month as well.
The first likely trouble is that qmail likes to rotate its own log files and by default (from memory) does this when they reach 10MB and keeps 4 of them. You will have to change your logging configuration either to tell qmail to keep more of them or to pipe them all through syslog and have syslog manage them.
The second is that timestamps in qmail are not human readable. Make sure you pipe everything through
tai64nlocal so you can read the timestamps.
Log files generated by qmail are different to other log files. You will want some help dealing with them.
There are some ready made tools for log analysis for Qmail.
You can use qmailanalog by djb himself but take care with what Ladadadada said about Qmail's log rotation.
There are 2 other tools that are a bit more analytical: