Pages

Saturday, December 29, 2012

Extracting all email addresses contained in emails.

Canyou help me, I extracted "from" addresses with the following script:

 

--script begins

property theBoxes : {"mailbox1", "mailbox2", "mailbox3", "mailbox4", "mailbox5", "mailbox6", "mailbox7"}

 

on run

          set theMessages to {}

          tell application "Microsoft Excel"

set theSpamFile to make new workbook

set theSheet to active sheet of theSpamFile

set formula of range "B1" of theSheet to "Subject"

set formula of range "A1" of theSheet to "From"

          end tell

          tell application "Mail"

set theRow to 2

get mailboxes

--set theMessages to messages of junk mailbox

repeat with aBox in theBoxes

set theMessages to theMessages & messages of mailbox aBox

end repeat

repeat with aMessage in theMessages

my SetFrom(sender of aMessage, theRow, theSheet)

my SetSubject(subject of aMessage, theRow, theSheet)

set theRow to theRow + 1

end repeat

end tell

 

end run

 

on SetFrom(theSender, theRow, theSheet)

          tell application "Microsoft Excel"

set theRange to "A" & 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 "B" & theRow

set formula of range theRange of theSheet to theSubject

          end tell

end SetSubject

--script ends

 

Which worked very well.

 

I now want to extract all of the to, cc and BCC emails and changed the above script to:

 

--script begins

property theBoxes : {"RWG Archive", "NRW Archive", "Contacts#Newspaper List", "JOBS R", "JOBS N"}

 

on run

          set theMessages to {}

          tell application "Microsoft Excel"

set theSpamFile to make new workbook

set theSheet to active sheet of theSpamFile

set formula of range "B1" of theSheet to "Subject"

set formula of range "A1" of theSheet to "Recipients"

          end tell

          tell application "Mail"

set theRow to 2

get mailboxes

--set theMessages to messages of junk mailbox

repeat with aBox in theBoxes

set theMessages to theMessages & messages of mailbox aBox

end repeat

repeat with aMessage in theMessages

my SetRecipients(recipients of aMessage, theRow, theSheet)

my SetSubject(subject of aMessage, theRow, theSheet)

set theRow to theRow + 1

end repeat

end tell

 

end run

 

on SetRecipients(theRecipients, theRow, theSheet)

          tell application "Microsoft Excel"

set theRange to "A" & theRow

set formula of (range theRange) of theSheet to theRecipients

          end tell

end SetRecipients

 

on SetSubject(theSubject, theRow, theSheet)

          tell application "Microsoft Excel"

set theRange to "B" & theRow

set formula of range theRange of theSheet to theSubject

          end tell

end SetSubject

--script ends

 

It does not work, I get the following error:

 

error "Can’t make «class trcp» 1 of «class mssg» id 135522 of «class mbxp» \"RWG Archive\" of application \"Mail\" into the expected type." number -1700 from «class trcp» 1 of «class mssg» id 135522 of «class mbxp» "RWG Archive"

 

I am not good at this and would appreciate help to get TO, CC and BCC address.

 

Kind Regard

 

 

o


 

 

 

o


View the original article here

0 comments:

Post a Comment