applescriptkeyboard-maestro

Send email from clipboard without opening mail.app


I searched for how to send email without opening apple mail, and found the question AppleScript - How to send a email without the mail app opening up

However, I'm doing this with Keyboard maestro, so that I can send a specific email using a hot key in any application. After googling for the solution I found this script that does the job well:

tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:"hello", content:"You got a new file in your Downloads folder, girl!", visible:true}
tell theNewMessage
    make new to recipient at end of to recipients with properties {address:"myemail@mail.com"}
    send
end tell

end tell

One problem: I want to do this, but instead of hello in the subject, I want to have the clipboard. Googling for that, I found two things

keystroke "v" using {command down}

or

return (the clipboard)

I tried to teplace "Hello" with those two. But none of them work.

I don't know applescript, thus googling around and my question here.


Solution

  • This worked for me:

    set a to "myemail@mail.com"
    tell application "Mail"
        tell (make new outgoing message)
            set subject to (the clipboard)
            set content to "content"
            make new to recipient at end of to recipients with properties {address:a}
            send
        end tell
    end tell