Logging incoming mail addresses

Hello,

I’m new here so sorry if this has been covered before.

We’ve recently run a competition on our website and then found out that mail.app will not export a list of received e-mail addresses. We found a solution to this to extract a list of mail addresses to list form but it was anything but elegant.

We used to use Quickmail which had an option to log all incoming mail to our mail server but Mail.app doesn’t seem to have an equivalent (if it does we haven’t found how to turn logging on).

Does anyone know of any script to log the mail addresses of incoming mail?

My applescripting is marginal to say the least and I wouldn’t really know where to begin with this.

I’m guessing it would be fairly simple to insert something between the incoming port on our mail server and the mail server app itself that would be able to parse the mail and extract the address in the From field and add to a list.

If anyone could point me in the right direction or fancies the challenge themselves (optimistic but worth a try) that would be great!

Many thanks,
Ben

Apologies,

I should have stated that our server is running 10.4.11 if that makes a difference.

Hi and welcome.

Try this, create a rule with condition every message and the action: run AppleScript and attach the script.
The log file will be created in ~/Library/Logs and can be read with Console.app like the other log files.
The subject and the sender address will be logged.
You can change the name of the log file in the property line


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
	try
		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
		try
			close access file logFile
		end try
		return false
	end try
end write_log

That’s great Stefan and works very well on a client machine.

Do you know if it’s possible to do something similar for the server though?
The Admin control on the x-serve doesn’t have the same interface as the mail app on the client side and doesn’t appear to allow you to add a rule in the same way.

It would obviously be easier for our administrator to collect logs from a single machine than to have to collect from around 20 client machines.

If it’s not possible at the server side then this works much better than the solution we had used before so many thanks Stefan. Much appreciated.

I’m sorry, I have no experiences at all with any server version of OS X

Thanks anyway Stefan, the script you posted is very useful.

Many thanks,
Ben