2013-08-06 37 views
1

我有一個註冊域,我使用hushmail作爲郵件提供者。我想從Mail.app發送電子郵件,就好像它們是從我的域發送的。出於安全原因(垃圾郵件),Hushmail SMTP服務器不允許使用與我的帳戶名稱不同的「發件人」地址。使用Applescript來設置「Reply-To」地址

我發現一種方法可以讓Apple郵件始終使用默認填充回覆郵件,這裏是:http://email.about.com/od/macosxmailtips/qt/etalwaysreplyto.htm但這對我來說過於激烈,因爲我的郵件客戶端中有多個郵件帳戶。

在Mail.app中,我可以手動設置「答覆到」字段,但Mail.app中沒有設置根據我選擇的郵箱自動填充。

到目前爲止,我有一個AppleScript,它能夠創建所選郵件的答覆:

tell application "Mail" 
    set theSelection to selection 
    if theSelection is {} then return 
    activate 

    repeat with thisMessage in theSelection 
     set theOutgoingMessage to reply thisMessage with opening window 


     # Wait for Mail.app to create the reply window 
     repeat until exists (window 1 whose name = "Re: " & subject of thisMessage) 
     end repeat 
     delay 0.1 

     # 
     # Here I want to set the reply-to address here based on the 
     # selected mailbox, or the "from" address of 
     # the current mail. 
     # 

     # 
     # The I need to restore the cursor to the body of the mail 
     # (if cursor was moved) 
     # 
    end repeat 
end tell 

我看了在AppleScript字典(文件 - >打開字典 - > Mail.app - >信息 - >信息 - >回覆),這似乎是我應該能夠設置一個屬性,但是當我做這樣的事情:

tell theOutgoingMessage 
make new recipient at end of reply to with properties {address:"[email protected]"} 

錯誤彈出說「郵件得到了一個錯誤:無法收到外發消息ID 65的回覆。「

我也試過

tell theOutgoingMessage 
set reply to to "[email protected]" 

但彈出一個錯誤說「郵件得到了一個錯誤:無法設置回覆傳出消息編號69的‘[email protected]

我怎樣才能回覆到設定我剛剛創建的回覆郵件的財產

+0

查看詞典顯示...回覆(text,r /​​ o)。 r/o表示這是一個只讀屬性,因此您將無法以編程方式進行設置。您只能以編程方式閱讀它。因此,您必須使用ui元素腳本技術來完成。 – regulus6633

回答

0

嘗試,如果這個工程:

make new recipient at end of to recipients with properties {address:"[email protected]"} 
+0

這並不能解決問題。它在「收件人」字段中添加收件人,但不在「收件人」字段中添加收件人。爲了清楚起見:當您選擇「查看」 - >「回覆地址字段」時,「回覆地址」字段將變爲可見。 – Rolf

+0

行動,你是對的,我現在看到。 從Mail AppleScript詞典看來,傳出消息類不支持對屬性的回覆。 我認爲唯一的解決方案是腳本gui,將下面的代碼添加到腳本的末尾: 告訴應用程序「系統事件」 應用程序進程前窗口的滾動區域1的設置值(文本字段1) 「郵件」到「[email protected]」 結束告訴 –

2

正如我在您的文章的評論中所述,您無法以編程方式設置回覆地址,因爲它是隻讀屬性。因此您需要使用腳本解決方案。

用戶界面腳本問題在於它不是一門精確的科學。如果蘋果改變了ui元素的位置,那麼你的腳本將停止工作。例如,我有Mail.app v6.5,並且可以使用「窗口1的滾動區域1的文本字段1」來引用回覆字段。在其他版本的Mail.app中可能不同(可能是)。

無論如何,在Mail.app的v6.5中,這將做你想要使用ui腳本。

tell application "Mail" 
    set theSelection to selection 
    if theSelection is {} then return 
    activate 

    repeat with thisMessage in theSelection 
     set replyToAddress to item 1 of (get email addresses of account of mailbox of thisMessage) 
     set replyToWindowName to subject of thisMessage 
     if replyToWindowName does not start with "Re:" then set replyToWindowName to "Re: " & replyToWindowName 

     -- open the reply message 
     set theOutgoingMessage to reply thisMessage with opening window 

     -- Wait for Mail.app to create the reply window 
     repeat until exists (window 1 whose name is replyToWindowName) 
      delay 0.2 
     end repeat 

     -- make sure the reply-to field is showing 
     my openReplyToField() 

     -- set the reply-to address here based on the selected mailbox 
     my setValueOfReplyToField(replyToAddress) 
    end repeat 
end tell 

on openReplyToField() 
    tell application "System Events" 
     tell process "Mail" 
      -- figure out if the reply-to text field is visible 
      set staticText to value of every static text of window 1 
      if staticText contains "Reply To:" then return 

      -- the reply-to field is not visible so we click the menu item 
      set viewMenu to menu 1 of menu bar item "View" of menu bar 1 
      set replyToMenuItem to first menu item of viewMenu whose name contains "Reply-To" 
      click replyToMenuItem 
     end tell 
    end tell 
end openReplyToField 

on setValueOfReplyToField(theValue) 
    tell application "System Events" 
     tell process "Mail" 
      set replyToField to text field 1 of scroll area 1 of window 1 
      set value of replyToField to theValue 
     end tell 
    end tell 
end setValueOfReplyToField 
+0

非常有希望。我有Mail 6.3,並且腳本不能用於開箱即用,但我正在嘗試將各種想法結合起來。你的腳本有一些偉大的指針。 – Rolf