Extract name and email from Mail via AppleScript

May 20, '04 09:07:00AM

Contributed by: gadg

It seems a lot of Applescripters are not aware of this support offered by Mail.app. When writing Applescripts for Mail, it's extremely easy to fetch the name and e-mail address of a sender ...

using terms from application "Mail"
  on perform mail action with messages theSelectedMessages
    tell application "Mail"
      repeat with eachMessage in theSelectedMessages
        set theSender to extract name from sender of eachMessage
        display dialog "name:" & theSender
        set theAddress to extract address from sender of eachMessage
        display dialog "address:" & theAddress
      end repeat
    end tell
  end perform mail action with messages
end using terms from
That's all there is to it!

Comments (1)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040517150751917