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

How to copy a file from a selected message to an outgoing message in outlook through 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 中处理文件的经验吗?

迪伦

似乎只在邮件之间传递附件不起作用,但首先保存附件然后将文件名传递给新附件的 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: 另一种选择是从传入消息中找到文件的位置,然后使用该别名而不是先保存它们,只是为了将它们添加到出站留言'