Accessing local mailboxes using applescript

Hi

Currently I have a POP account. I have created folders on mail.app to store emails. The incoming mails are redirected to the these folders using rules in mail.app.

I want to be able to access the unread mails stored in these folders and process them using Applescript. However applescript cannot find these folders or the emails stored in them…

Can somebody pls help me??

Thanks
Sumi

Hi

I’m not sure what you want to do when processing the emails in these folders but here’s how you would get the contents of
a particular email in a folder.

tell application "Mail"
	set t to content of message 2 of mailbox "Misc" -- or you could say mailbox 1 etc.
end tell
t -- the message body of the email

this was tested on an “imap” account but i couldn’t see why it wouldn’t work on a “pop” account.

Thanks pidge 1. The given code only works for an IMAP account. Its not working for a POP account. The applescript fails to find any mailbox for a POP account

Hi,

custom created subfolders can be referenced separated by slashes e.g.

mailbox "folder1/folder2"

hi

thanks stefank but "mailbox “folder1/folder2” didnt work either.

This is because if you have a POP account the only mailbox applescript recognises is “INBOX”. As for the custom made mailboxes on mail.app, it isn’t able to recognise or find them.

Any idea how I can access those mailboxes using applescript

Sumi

I don’t know your folder structure,
but you can access every folder with AppleScript, you can create in Mail.

The custom folders ON MY MAC are not inherited by any account,
mailbox is also a top level element of application.
Unfortunately you can’t get the full “paths” of the mailboxes directly, but a forced error helps


tell application "Mail"
	set theMailBoxes to {}
	repeat with oneBox in mailboxes
		try
			oneBox as number -- throws always an error
		on error e
			set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, quote}
			set end of theMailBoxes to text item 2 of e
			set AppleScript's text item delimiters to ASTID
		end try
	end repeat
end tell
theMailBoxes