Send email from clipboard without opening mail.app

2019-05-21 03:41发布

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.

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-05-21 04:25

Here's a script that happens to work for me very well. I'll just post it as an example.

tell application "System Events"
    activate application "Mail"
    set the clipboard to "Subject Line"
    keystroke "v" using command down
    keystroke tab
    set the clipboard to "This is the contents.\nLine 2 of the contents."
    keystroke "v" using command down
end tell

I use this script after clicking on an e-mail address in the browser. I choose the relevant Mail script from my AppleScript menu after making sure that the text insertion point is in the subject line of my e-mail.

查看更多
干净又极端
3楼-- · 2019-05-21 04:29

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
查看更多
登录 后发表回答