Hoping someone can help.
I have a great AppleScript that allows me to export mail headers to excel.
Only problem is it references the account you select and a specific mailbox but it doesn't iterate through every sub mailbox contained within the first mailbox.
Is there a way to loop through all mailboxes of a mailbox
tell application "Microsoft Excel"
set theSpamFile to make new workbook
set theSheet to active sheet of theSpamFile
set formula of range "c1" of theSheet to "Subject"
set formula of range "b1" of theSheet to "From"
set formula of range "a1" of theSheet to "To"
set formula of range "d1" of theSheet to "Date"
end tell
tell application "Mail"
set theRow to 2
set theAccounts to every account
set accountChoices to {}
repeat with theAccount in theAccounts
set the end of accountChoices to (name of theAccount as string)
end repeat
set theResult to (choose from list accountChoices with prompt "Choose one." without multiple selections allowed) as rich text
set theAccount to the account theResult
set theBox to some mailbox
set thePath to name of theBox
repeat
try
set theBox to container of theBox
set thePath to name of theBox & "/" & thePath
on error
exit repeat
end try
end repeat
set theMessages to every message in the mailbox "Reports" of theAccount
repeat with aMessage in theMessages
my SetFrom(sender of aMessage, theRow, theSheet)
my SetSubject(subject of aMessage, theRow, theSheet)
my Setto(address of to recipients of aMessage, theRow, theSheet)
my Setdate(date received of aMessage, theRow, theSheet)
set theRow to theRow + 1
end repeat
end tell
on SetFrom(theSender, theRow, theSheet)
tell application "Microsoft Excel"
set theRange to "b" & theRow
set formula of (range theRange) of theSheet to theSender
end tell
end SetFrom
on SetSubject(theSubject, theRow, theSheet)
tell application "Microsoft Excel"
set theRange to "c" & theRow
set formula of range theRange of theSheet to theSubject
end tell
end SetSubject
on Setto(therecipients, theRow, theSheet)
tell application "Microsoft Excel"
set theRange to "a" & theRow
set formula of range theRange of theSheet to therecipients
end tell
end Setto
on Setdate(thedatereceived, theRow, theSheet)
tell application "Microsoft Excel"
set theRange to "D" & theRow
set formula of range theRange of theSheet to thedatereceived
end tell
end Setdate
question from:
https://stackoverflow.com/questions/65838656/applescript-mail-app-how-to-extract-email-headers-from-a-mailbox-with-multip 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…