设置外发邮件的内容失败

时间:2015-11-27 15:35:28

标签: email applescript

我试图创建一个自动回复脚本,但是当我尝试设置外发邮件的内容时,它会抛出一个错误并告诉我“内容”无法读取。

set replyMessage to reply thisMessage with opening window
delay 2
set rich text content of replyMessage to "Hallo"

任何想法?

编辑:完整代码:

tell application "Mail"
    set replyList to {}
    set inboxMessages to every message in inbox

    # get Einsatz mail from all emails
    repeat with thisMessage in inboxMessages
        set thisContent to content of thisMessage
        set thisSender to sender of thisMessage

        if thisSender contains "@pos-lifestyle.de" then
            if thisContent contains "nochmal alle wichtigen Informationen zum Heimspiel" then
                if thisContent contains "deinen Einsatz per Mail" and thisContent contains "Bitte bestätige" then
                    set end of replyList to thisMessage
                    set read status of thisMessage to true
                end if
            end if
        end if
    end repeat


    # reply to all Einsatz mails
    repeat with thisMessage in replyList
        set replyMessage to reply thisMessage with opening window
        delay 2
        set content of replyMessage to (("Hallo," & return & "hiermit bestätige ich den Einsatz." & return & "Mit besten Grüßen" & return & "Max Mustermann") as rich text)
    end repeat
end tell

2 个答案:

答案 0 :(得分:1)

我现在根据您的最新更新完成完整脚本。 我用几个案例测试了它,它100%为我工作。我做了几个简化。 此外,我已经在脚本之上设置了目标(发件人和内容),以便于阅读和测试(测试时,我只需要在邮箱上用可能的值更改4行的值!)。

set TargetSend to "@pos-lifestyle.de"
set Target1 to "nochmal alle wichtigen Informationen zum Heimspiel"
set Target2 to "deinen Einsatz per Mail"
set Target3 to "Bitte bestätige"

tell application "Mail"
set replyList to {}
set inboxMessages to every message in inbox whose sender contains TargetSend
repeat with thisMessage in inboxMessages
    set thisContent to content of thisMessage
    if (thisContent contains Target1) and (thisContent contains Target2) and (thisContent contains Target3) then
        set end of replyList to thisMessage
        set read status of thisMessage to true
    end if
end repeat

# reply to all Einsatz mails
repeat with thisMessage in replyList
    set replyMessage to reply thisMessage with opening window
    delay 2
    set content of replyMessage to (("Hallo," & return & "hiermit bestätige ich den Einsatz." & return & "Mit besten Grüßen" & return & "Max Mustermann") as rich text)
end repeat
end tell

答案 1 :(得分:0)

我想出了一种防止这种错误发生的方法

set TargetSend to "@pos-lifestyle.de"
set Target1 to "nochmal alle wichtigen Informationen zum Heimspiel"
set Target2 to "deinen Einsatz per Mail"
set Target3 to "Bitte bestätige"
set MyName to "Max Musterman"

tell application "Mail"
    set replyList to {}
    set inboxMessages to every message in inbox whose sender contains TargetSend

    # look for Einsatz mails
    repeat with thisMessage in inboxMessages
        set thisContent to content of thisMessage
        if (thisContent contains Target1) and (thisContent contains Target2) and (thisContent contains Target3) then
            set end of replyList to thisMessage
            set read status of thisMessage to true
        end if
    end repeat

    # reply to all Einsatz mails
    repeat with thisMessage in replyList
        set replyMessage to reply thisMessage with opening window
        repeat until exists (window 1 whose name = "Re: " & subject of thisMessage)
        end repeat
        delay 0.1

        tell application "System Events"
            tell process "Mail"
                set frontmost to true
                keystroke "Hallo"
                keystroke return
                keystroke "Hiermit bestätige ich den Einsatz."
                keystroke return
                keystroke "Mit besten Grüßen"
                keystroke return
                keystroke MyName
                keystroke return
            end tell
        end tell

        #send replyMessage

    end repeat
end tell