Logging mail on 10.4 server running Apple mail server

Discussion in 'Mac OS X Server, Xserve, and Networking' started by Ben Kei, Aug 13, 2008.

  1. Ben Kei macrumors regular

    Oct 30, 2002
    London UK

    In the past we had used Quickmail in our offices which had an option to export a log of all sent/received mail.

    Does anyone know if it's possible to do the same in OS X mail server? (using 10.4.11)

    We've run a competition on our site and need to be able to get all the entries into list form otherwise some poor soul will be sitting down and extracting about 4000 mail addresses.

    Many thanks,
  2. Ben Kei thread starter macrumors regular

    Oct 30, 2002
    London UK
    For anyone who is interested.

    While we haven't yet found a way to do this on the server, someone has written us an applescript that will log all incoming mail addresses on the client side.

    You'll need to paste the script into the applescript editor and save as a scpt file.

    Create a rule in Mail:

    If - [all] of the following conditions are met:
    [every message]
    Perform the following actions:
    [run apple script]

    Then select the script.

    This will create a log file in your console.app and write the address and title of all incoming e-mails.

    I hope this is useful to someone and thanks to user StefanK on the Macscripter website who wrote the script for us.


    property logName : "IncomingMailAddresses.log"

    using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
    repeat with oneMessage in theMessages
    tell oneMessage to set {theAddress, theSubject} to {sender, subject}
    write_log of me from theSubject & " - " & theAddress
    end repeat
    end perform mail action with messages
    end using terms from

    on write_log from theMessage
    tell (current date) to set timestamp to short date string & space & time string & ": "
    set logFile to ((path to library folder from user domain as text) & "Logs:") & logName
    set the logStream to open for access file logFile with write permission
    set logFileEof to get eof of the logStream
    write timestamp & theMessage & return to logStream starting at eof as «class utf8»
    close access logStream
    return true
    on error
    close access file logFile
    end try
    return false
    end try
    end write_log

Share This Page