Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How can I log all emails going through sSMTP?

I can point my applications to a wrapper script, I just don't know how to write a wrapper script which logs headers and contents to a file (as much information as possible).

Thanks! :-)

share|improve this question

3 Answers 3

up vote 4 down vote accepted

The following should work as an sSMTP wrapper script. It logs the parameters it is called with and the data provided on stdin. Change the logfile location and name of the real sSMTP as appropriate.

#!/bin/sh
set -e
LOGFILE="/tmp/ssmtp-$(date +%Y%m%d-%H%M%S-$$)"
echo "$0 $@" > "$LOGFILE"
tee -a "$LOGFILE" | ssmtp.real "$@"

Remember to make the script executable:

chmod +x /path/to/script

share|improve this answer
    
That's just amazing, thanks! –  Thomas Jensen Jul 3 '12 at 20:01
    
Can I log the response from Amazon to the log file as well? –  Thomas Jensen Oct 4 '12 at 9:32

sSMTP has debug logging built in. In your ssmtp.conf file, include the following line: Debug=YES

When debug logging is active, the entire contents of emails sent via sSMTP, including headers, is logged to syslog.

share|improve this answer

Why don't you just have your SMTP server log all of the messages received, hence capture the entire message?

If you use an external server you could just setup a simple internal server that then relays to the external server.

share|improve this answer
    
I use Amazon SES, which doesn't provide logging. I thought sSMTP was that simple internal server? –  Thomas Jensen Jul 3 '12 at 19:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.