2014-09-20 55 views
0

的身體我想要做的是完全一樣的,因爲這從下面從AppleScript;複製HTML .rtf文件到電子郵件

set the clipboard to (read "/Users/kiara/Desktop/mailer/technology/tech-en-content.rtf" as «class RTF ») 

tell application "Mail" 
    activate 
    set theMessage to make new outgoing message with properties {visible:true, subject:"mysubject"} 
end tell 

tell application "System Events" 
    tell process "Mail" 
     repeat until focused of UI element 1 of scroll area 4 of window 1 
      keystroke tab 
     end repeat 
     keystroke "v" using command down 
    end tell 
end tell 

參考鏈接:Copying .rtf text into the body of an email with AppleScript

但它不工作,我Mac條件OS X小牛隊

請任何人都給我如何撰寫一個HTML電子郵件與AppleScript。

乾杯,

回答

1

你正在做的事情是行不通的。無論您將什麼粘貼到電子郵件中,都會以文本形式粘貼。它只是不起作用。你可以嘗試它,但它不會工作。你遇到麻煩的原因是因爲它是最新版本的郵件中的「滾動區域1」,而不是4.

但是有一種方法可行。郵件有一些叫做「html內容」的東西。所以,如果你有HTML代碼,那麼你可以設置一個消息的「HTML內容」到該HTML代碼。雖然有一個警告。這似乎是一個錯誤,但如果你設置了郵件的html內容,那麼出於某種原因你看不到它。你可以發送它,它會正常工作......但你看不到它。正因爲如此,我通常將消息的可見性設置爲false,並將其與applescript一起發送。

無論如何,既然你有一個rtf文件,你需要使用命令行工具「textutil」將rtf轉換爲html代碼,這樣你纔可以將html放入消息中。

試試這個。首先設置一個接收器和主題。祝你好運。

set rtfFile to "/Users/kiara/Desktop/mailer/technology/tech-en-content.rtf" 
set receiver to "[email protected]" 
set theSubject to "This is the subject" 

set htmlCode to do shell script "/usr/bin/textutil -stdout -format rtf -convert html " & quoted form of rtfFile 

tell application "Mail" 
    set newMessage to make new outgoing message at end of outgoing messages with properties {visible:false} 
    tell newMessage 
     make new to recipient at end of to recipients with properties {address:receiver} 
     set subject to theSubject 
     set html content to htmlCode 
     delay 0.5 
     send 
    end tell 
end tell 
+0

非常感謝您的支持。 – user1574429 2014-09-21 13:17:29

+0

非常感謝您的建議。我試過這段代碼似乎可行,但我認爲我的HTML代碼在這種情況下會有所不同。我的HTML代碼,以此爲出發點: <!DOCTYPE HTML> 通訊 <風格類型= 「文/ CSS」> TD { FONT-FAMILY:宋體,Arial字體,無襯線; font-size:12px; color:#fff; } p { margin:0 0 12px 0; } 在這段代碼中,我怎麼能設置成郵件的正文使用AppleScript? 謝謝! – user1574429 2014-09-21 13:20:03

相關問題