创建Applescript以通过电子邮件发送文件

时间:2014-11-23 01:18:56

标签: applescript automator

我希望Apple邮件应用程序接受并发送电子邮件给我,然后通过电子邮件将文件发送给我。例如,我想发送一封主题为“#FILE myfile.doc”的电子邮件,并且由于主题中的#FILE标记而触发脚本,然后通过电子邮件回复名为“myfile.doc”的文件。

文件将始终位于相同的路径中,但能够在脚本中指定路径以便为不同的目录创建不同的路径会很好。

我对Applescript一无所知,并涉足Automator。我只在Mail中看到你可以从规则中触发Applescript。所以我不知道这是否可以在Automator中完成。

请基本回答您的回复,因为我是新手。

目的是在我离开时从我的电脑上取下一个文件。

谢谢, ROY

1 个答案:

答案 0 :(得分:0)

您可以使用Mail中的邮件规则来执行此操作。指定您的电子邮件地址作为发件人,主题以#FILE开头。让邮件规则触发这样的脚本:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        tell application "Mail"
            repeat with thisMessage in theMessages
                set theSender to sender of thisMessage
                set theSubject to subject of thisMessage
                if theSubject begins with "#FILE " then
                    set theAnswer to make new outgoing message with properties {visible:true}
                    tell theAnswer
                        try
                            tell current application
                                set theFilePathToSend to (POSIX file (text 7 thru -1 of theSubject)) as alias
                            end tell
                            set content to "And here is your file: " & rich text 7 thru -1 of theSubject & return & return
                            tell content to make new attachment with properties {file name:theFilePathToSend} at after the last paragraph
                        on error errStr
                            set content to "An error occured: " & return & errStr
                        end try
                        set subject to "Re: " & theSubject
                        make new to recipient at end of to recipients with properties {address:theSender}
                        send
                    end tell
                end if
            end repeat
        end tell
    end perform mail action with messages
end using terms from

使用reply - 处理程序不起作用,但make new outgoing message做了!指定文件的完整路径作为主题。

请注意,这是一个安全漏洞!发件人的电子邮件地址可以伪造,有人知道这可以得到他(或她)想要的几乎所有文件。您可以在此脚本中指定允许的文件夹,即if theSubject begins with "#FILE /Users/rbarr/Desktop/Available files/" then或仅通过调整触发邮件规则的条件。

享受,迈克尔/汉堡

相关问题