Send email from clipboard without opening mail.app

佐手、 提交于 2019-12-10 11:09:27

问题


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.


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/18041535/send-email-from-clipboard-without-opening-mail-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!