如何通过applescript将文件从选定的邮件复制到外发邮件?

时间:2015-06-11 17:26:28

标签: outlook applescript

我一直试图弄清楚如何通过applescript将Outlook中传入邮件中的附件复制到新的传出邮件中。

下面的代码是我到目前为止所得到的,但这绝对是错误的。 Outlook抛出错误并指出错误:“ Microsoft Outlook出错:无法将缺失值存入类型文件。

tell application "Microsoft Outlook"

-- get the incoming message
set objMessage to item 1 of (get current messages)
set myMessage to make new outgoing message

-- iterate through attachments
-- for each attachment make a new attachment in the message to send identical properties
-- ???
repeat with _attachment in attachments of objMessage
    set n to name of _attachment
    set ct to content type of _attachment
    set f to file of _attachment
    set fs to file size of _attachment
    tell myMessage
        make new attachment with properties {name:n, content type:ct, file:f, file size:fs}
    end tell

end repeat

open myMessage


end tell

我已经尝试过其他一些东西,但我似乎无法获取传入邮件附件的文件属性。

有没有人以这种方式使用Outlook和Applescript中的文件?

1 个答案:

答案 0 :(得分:0)

迪伦

似乎只是在消息之间传递附件并不起作用,但首先保存附件,然后将文件名传递给新附件的file属性。

tell application "Microsoft Outlook"
    local mynames, msg1, msg2, saveToFolder, saveAsName
    set msg1 to last item of incoming messages
    set msg2 to make new outgoing message with properties {subject:"Testing this thing"}
    set saveToFolder to POSIX path of (path to desktop)
    repeat with atts in attachments of msg1
        set saveAsName to saveToFolder & (name of atts)
        log saveAsName
        save atts in saveAsName
        tell msg2
            make new attachment with properties {file:saveAsName} -- with properties {file:atts}
        end tell
    end repeat
    open msg2
end tell

注1:您可能需要添加逻辑来删除从传入邮件中保存的文件(原始附件)。

注意2:另一种选择是从收到的邮件中找到文件的位置,然后只使用该别名而不是先保存它们,只是为了将它们添加到出站邮件中&#39; < / p>