Howt check sent emails per account?

Is there anyway I can check the number of outgoing emails per virtual server or domain - per month?

Thanks.

Anyone have any ideas on this?

I am weighing up whether to use mailchimp (or similar) but need to know how many emails I am sending out a month before committing :stuck_out_tongue:

Howdy,

Hmm, I don’t think there’s any information on how many emails per domain or account were sent. But, there are bandwidth related totals, that may at least be a start… you can see total bandwidth used for email by looking in System Settings -> Bandwidth Monitoring -> Show Usage Graph, and then look for the green section of the usage graph.

There are other tools that can help you figure that out though – I’ve used things like pflogsumm to determine that in the past.

-Eric

Hi Eric, thanks for the reply.

I saw someone mentioned that cPanel shows these stats so wondered if VM did too. Not a big problem, I will just try it and see how it goes - if it works out too expensive I will revert :smiley:

I played around with the mail.log and “pflogsumm” a bit.

If it’s just about finding out how much mail your server is sending out in general, you could use the “logtail” command on /var/log/mail.log, and feed its output to something like

egrep "smtp.*status=sent" mail.log | wc -l

Getting an actual per-local-domain breakdown is more difficult though. pflogsumm won’t be an overly big help there since it doesn’t differentiate between local and remote senders in its summaries. Also note that authenticated users normally can use any sender email address, and don’t necessarily have to use one that corresponds to their actual domain, so the log would “lie” in that regard.

The only reliable information for outgoing email is the authenticated user (ignoring local sending by PHP scripts and so on). So you’d need to parse the mail log, considering a block like so:

Feb 8 19:46:22 SERVERHOST postfix/smtpd[13193]: B64FC44FA7: client=HOST[IP], sasl_method=PLAIN, sasl_username=AUTH_USER_ACCOUNT [...] Feb 8 19:46:22 SERVERHOST postfix/qmgr[2092]: B64FC44FA7: from=<sender>, size=649, nrcpt=1 (queue active) [...] Feb 8 19:46:23 SERVERHOST postfix/smtp[13202]: B64FC44FA7: to=<recipient>, relay=RECIPIENT_MAIL_SERVER[IP]:25, delay=0.78, delays=0.14/0.04/0.5/0.1, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as CFE1180071)

You’d need to analyse this block and match up the delivery by the local user (which gives you the authentication account), and subsequent sending of the email (which tells you that the mail was actually delivered), and then extract the domain from the account name. The matching can probably be done using these queue ID numbers (here B64FC44FA7), which should stay the same for the whole process.

Thanks Locutus, I will try giving that a go.

thought this might be useful information:

php has a logging function you can use to determine who is sending mail from apache2.

; Add X-PHP-Originating-Script: this will include UID and script filename in outgoing mail to track abuse mail.add_x_header = On

; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
mail.log = /var/log/audit/php.mail.log

you will want to make /audit/ have permissions to prevent snooping or abuse; php.mail.log should also have maybe chattr +a, sticky bit, or other hard permissions, be owned by root, but rw_rw_rw so that fcgid can write to it as any user

finally, might want to add this to a lone .ini under /etc/php5/conf.d/ so that the user cannot over write