2015-12-20 19 views
0

我已經編寫了 - 當然有各種來源的幫助 - 這個腳本來批量重定向郵件:它重定向郵件應用程序中選定的所有郵件。似乎沒有什麼特別的事情發生。如何對使用重定向創建的郵件執行操作?

tell application "Mail" 
    set AppleScript's text item delimiters to "" 
    set theRedirectRecipient to "[email protected]" 
    set theRedirectSender to "Sender" 
    set theMessages to the selection 

    repeat with thisMessage in theMessages 
     tell application "Mail" 
      set theRedirectedEmail to redirect thisMessage with opening window 
      tell theRedirectedEmail 
       if subject of thisMessage is "" then 
        set subject of theRedirectedEmail to "Mails zonder subject" 
       end if 

       make new to recipient at beginning of to recipients with properties {address:theRedirectRecipient} 
       #delete bcc recipients 
       #delete cc recipients 
      end tell 
      #delay 2 
      #send theRedirectedEmail 
     end tell 
    end repeat 
end tell 

如上所述,腳本運行正常:它創建重定向郵件,如果我按下發送按鈕,它就像我需要的那樣工作。

但有3行註釋不起作用。刪除行和發送行。我真的不確定我是否在意刪除的內容,但是我已經將它們包括在內以防某些人看到某種模式。

在取消這些行的人給我這個錯誤:

error "Mail got an error: Can’t get every cc recipient of outgoing message id 18." number -1728 from every cc recipient of outgoing message id 18

而且,這並創建一個消息窗口,如果用手工完成的,我可以成功發送。

在取消「發送」行引入了以下錯誤:

error "Mail got an error: outgoing message id 19 doesn’t understand the 「send」 message." number -1708 from outgoing message id 19

因此,我得出的結論是,所創建的消息不表現爲一條消息「應該」。我看到this thread關於似乎顯示此行爲的「傳出消息」。

這條消息是怎麼回事theRedirectEmail?如何將消息發送到此對象,如deletesend

回答

1

我注意到這個問題。這是我想出的解決方法。在某些方面,它其實更容易:

tell application "Mail" 
    set AppleScript's text item delimiters to "" 
    set theRedirectRecipient to "[email protected]" 
    set theRedirectSender to "Sender" 
    set theMessages to the selection 

    repeat with thisMessage in theMessages 
     redirect thisMessage with opening window 
     tell application "System Events" 
      tell application process "Mail" 
       tell window 1 

        --wait for mail message to appear before continuing 

        repeat while not (text field "To:" exists) 
        end repeat 

        set value of text field "To:" to theRedirectRecipient 
        set value of text field "Cc:" to "" 
        if text field "Bcc:" exists then 
         set value of text field "Bcc:" to "" 
        end if 
        if value of text field "Subject:" is equal to "" then 
         set value of text field "Subject:" to "Mails zonder subject" 
        end if 
       end tell 
       tell application "Mail" to activate 
       click menu item "Send" of menu 1 of menu bar item "Message" of menu bar 1 
      end tell 
     end tell 
    end repeat 
end tell 

你必須告訴郵件激活,因爲郵件不允許電子郵件的發送時,它在後臺運行,可能以防止犯罪分子從垃圾郵件整個聯繫人在不知情的情況下使用AppleScript在後臺列出。這可能與郵件中有關傳出郵件的奇怪行爲有關,儘管我不能確定...

+0

好吧,我想我明白了,但我沒有得到它與重複工作我'使用;你基本上使用了2步法,有2個'tell'塊,但是由於我在那個循環中,我不確定知道該怎麼做的applescript。有關如何將您的示例與我的代碼合併的任何提示? – Nanne

+0

對不起,我很懶。我用合併版本更新了它。它應該做的伎倆。 –

+0

謝謝!我並不熟悉applescript,因爲你可能已經收集到了,這對我有幫助:D – Nanne

相關問題