Apple Intelligence now features Image Playground, Genmoji, Writing Tools enhancements, seamless support for ChatGPT, and visual intelligence.

Apple Intelligence has also begun language expansion with localized English support for Australia, Canada, Ireland, New Zealand, South Africa, and the U.K. Learn more >

You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Exporting Email to Numbers

I am looking for a solution for exporting email....


Currently, I can export the contents of an email inbox (Apple's Native Email) into an .mbox file. I am needing to get this email information into Numbers so that I can process multiple emails at a time.


The emails are structured from a website form so that every email will have the same content. I am needing the following from the emails:

  1. Email Address
  2. Name of the Emailer
  3. Date of the Email
  4. Time of the Email
  5. Body of the Email


I would then filter through the emails in numbers.


How can I accomplish this task.....AppleScript seems like a likely option, but I would need to export the entire inbox at one time.....I could potentially have more than 1000 emails during a week.

MacBook Pro 16″, macOS 10.15

Posted on Aug 17, 2021 6:25 AM

Reply
Question marked as Top-ranking reply

Posted on Aug 17, 2021 10:51 AM

You can try the script below:


set dataLst to {{"SenderAddress", "SenderName", "Date", "Time", "Content"}}

tell application "Mail"
	repeat with aMsg in items of (get selection)
		tell aMsg
			set senderNameAddr to my splitEmail(sender)
			set senderAddr to item 2 of senderNameAddr
			set senderName to item 1 of senderNameAddr
			set msgSubj to subject
			set msgDate to date received
			set msgTime to time string of msgDate
			set msgDate to my dateFormat(date string of msgDate)
			set msgContent to content
			set msgLst to {senderAddr, senderName, msgDate, msgTime, msgContent}
			copy msgLst to dataLst's end
		end tell
	end repeat
end tell

tell application "Numbers"
	set newDoc to make new document
	tell table 1 of active sheet of newDoc
		delete column "A" -- remove default Header Column
		set column count to length of item 1 of dataLst
		set row count to (length of dataLst)
		repeat with i from 1 to length of dataLst
			repeat with j from 1 to length of item 1 of dataLst
				set value of cell j of row i to item j of item i of dataLst
			end repeat
		end repeat
	end tell
end tell

to dateFormat(aDateString) --> yyyy-mm-dd
	set {year:y, month:m, day:d} to date aDateString
	tell (y * 10000 + m * 100 + d) as string to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8
end dateFormat

to splitEmail(nameAddress)
	set text item delimiters to "<"
	tell nameAddress
		set theName to text item 1
		set theAddress to text 1 thru -2 of text item 2
	end tell
	return {theName, theAddress}
end splitEmail


  1. Copy-paste into Script Editor (in Applications > Utilities)
  2. Select the messages in an email box in the Mail app (not the .mbox file)
  3. Click the run button
  4. Watch the Running... indicator at the bottom of Script Editor (it could easily take several minutes to finish doing its thing).


Finally a new Numbers document should pop up with the information from the selected mail messages.


SG

2 replies
Question marked as Top-ranking reply

Aug 17, 2021 10:51 AM in response to Lester2k1

You can try the script below:


set dataLst to {{"SenderAddress", "SenderName", "Date", "Time", "Content"}}

tell application "Mail"
	repeat with aMsg in items of (get selection)
		tell aMsg
			set senderNameAddr to my splitEmail(sender)
			set senderAddr to item 2 of senderNameAddr
			set senderName to item 1 of senderNameAddr
			set msgSubj to subject
			set msgDate to date received
			set msgTime to time string of msgDate
			set msgDate to my dateFormat(date string of msgDate)
			set msgContent to content
			set msgLst to {senderAddr, senderName, msgDate, msgTime, msgContent}
			copy msgLst to dataLst's end
		end tell
	end repeat
end tell

tell application "Numbers"
	set newDoc to make new document
	tell table 1 of active sheet of newDoc
		delete column "A" -- remove default Header Column
		set column count to length of item 1 of dataLst
		set row count to (length of dataLst)
		repeat with i from 1 to length of dataLst
			repeat with j from 1 to length of item 1 of dataLst
				set value of cell j of row i to item j of item i of dataLst
			end repeat
		end repeat
	end tell
end tell

to dateFormat(aDateString) --> yyyy-mm-dd
	set {year:y, month:m, day:d} to date aDateString
	tell (y * 10000 + m * 100 + d) as string to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8
end dateFormat

to splitEmail(nameAddress)
	set text item delimiters to "<"
	tell nameAddress
		set theName to text item 1
		set theAddress to text 1 thru -2 of text item 2
	end tell
	return {theName, theAddress}
end splitEmail


  1. Copy-paste into Script Editor (in Applications > Utilities)
  2. Select the messages in an email box in the Mail app (not the .mbox file)
  3. Click the run button
  4. Watch the Running... indicator at the bottom of Script Editor (it could easily take several minutes to finish doing its thing).


Finally a new Numbers document should pop up with the information from the selected mail messages.


SG

Exporting Email to Numbers

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.