如何使用AppleScript和文本文件创建活动电子邮件?

时间:2013-11-28 12:18:43

标签: outlook applescript outlook-addin osx-mavericks

我必须使用文本文件作为模板创建Outlook电子邮件。我看过一些剧本,但没有像我需要的那样。我还需要在创建电子邮件之前编辑文件的某些内容。我还需要知道放置该模板文件的最佳位置。

有一个用于创建新电子邮件的脚本,但我不知道如何从此处加载测试和编辑。

更新了代码----

    --read source from the file

set theFile to "/Users/eclit/Desktop/MeetingTemplate.html"
open for access theFile
set fileContents to (read theFile)
close access theFile

tell application "Microsoft Outlook"

    set newMessage to make new outgoing message with properties {subject:"Hooray for automation", content:fileContents & return & return}
    make new recipient at newMessage with properties {email address:{name:"Jim Shank", address:"jim.shank@example.com"}}
    open newMessage
end tell

请帮忙。

1 个答案:

答案 0 :(得分:0)

    --read source from the file

set theFile to "/Users/eclit/Desktop/MeetingTemplate.html"
open for access theFile
set fileContents to (read theFile)
close access theFile

on replaceText(find, replace, subject)
    set prevTIDs to text item delimiters of AppleScript
    set text item delimiters of AppleScript to find
    set subject to text items of subject

    set text item delimiters of AppleScript to replace
    set subject to "" & subject
    set text item delimiters of AppleScript to prevTIDs

    return subject
end replaceText

-- log fileContents

on categoryForName(_categoryName)
    tell application "Microsoft Outlook"
        try
            return category _categoryName
        on error
            try
                -- Getting by name doesn't always work.
                repeat with _category in categories
                    if _category's name is _categoryName then return _category
                end repeat
            end try
            make new category with properties {name:_categoryName}
        end try
        return category _categoryName
    end tell
end categoryForName

log fileContents

tell application "Microsoft Outlook"
    --set newMessage to make new outgoing message with properties {subject:"Hooray for automation", content:fileContents & return & return}
    set theCategory to my categoryForName("Work")
    --set theCategory to make new category with properties {name:"Fanciful", color:{12345, 23456, 11111}}
    set newEvent to make new calendar event with properties {subject:"Dial In : +442034333797  Conference code: 5270687926", content:fileContents}
    --make new recipient at newMessage with properties {email address:{name:"Jim Shank", address:"jim.shank@example.com"}}
    --open newMessage
    open newEvent
end tell