Search code examples
macosapplescriptapple-mail

How to retrieve email body of outgoing mail in apple mail using applescript?


How can i retrieve email body, recipient email address, subject etc of outgoing mail.

thanks for any help.

EDIT:- I have added one custom button in outgoing mail toolbar see image.

enter image description here

And the functionality of that button is send mail and save all mail detail on my server also so how can i get that detail like, both email addresses "To"="test@gmail.com" and "cc"="test2@gmail.com", subject="My subject" , and email body="My email body"

How can i achieve this ?


Solution

  • Through this apple script you can retrieve mail content so please try it.

    tell application "System Events"
        tell process "Mail"
            set _Contents to {}
            set _contentDetail to {}
            set the _contentDetail to entire contents of UI element 1 of scroll area 3 of window 1
            repeat with _value in _contentDetail
                set str to ""
                if class of _value is static text then
                    set str to value of _value
                end if
                set str to str & return
                set _Contents to _Contents & str
    
            end repeat
            return get _Contents as string
        end tell
    end tell