是否可以在Mac上自动从Outlook中提取邮件?

Is it possible to extract mails from Outlook automatically on Mac?

提问人:ph13 提问时间:7/19/2023 更新时间:7/19/2023 访问量:42

问:

我正在尝试使用 AppleScript 从 Mac 上的 Outlook 导出邮件,因为它不适用于 VBA。但是,我没有取得很大进展,文本文件没有保存到我的桌面,这就是为什么它总是以空的 Excel 工作表停止的原因。有什么提示吗?

-- 第 1 步:将带有红色类别的电子邮件导出到文本文件 将 desktopFolderPath 设置为(桌面路径)作为文本

告诉应用程序“Microsoft Outlook” 将 redCategoryName 设置为“Red”

set redEmails to {}
set allEmails to every message of inbox
repeat with anEmail in allEmails
    if (subject of anEmail) contains redCategoryName then
        set end of redEmails to anEmail
    end if
end repeat

结束告诉

-- 将带有红色类别的电子邮件导出到文本文件 告诉应用程序“Microsoft Outlook” 在 redEmails 中使用 redEmail 重复 设置 emailSubject to subject of redEmail 将 receivedTime 设置为 redEmail 的 receivedTime 将 filePath 设置为 desktopFolderPath & (my formatReceivedTime(receivedTime) & “_” & emailSubject & “.txt”)

    set mailBody to content of redEmail
    
    set fileRef to open for access file (POSIX file filePath) with write permission
    write mailBody to fileRef
    close access fileRef
end repeat

display alert "Emails with the Red category have been exported to text files."

结束告诉

-- 第 2 步:从文本文件中提取过滤后的信息并写入 Excel 文件 告诉应用程序“Microsoft Excel” 将 excelFilePath 设置为 desktopFolderPath -- 替换为所需的 Excel 文件路径

set newWorkbook to make new workbook

tell newWorkbook
    set activeSheet to active sheet
    set rowIndex to 2 -- Start from row 2 for data
    
    set cellValue of range "A1" of activeSheet to "Sender"
    set cellValue of range "B1" of activeSheet to "Email Reference"
    set cellValue of range "C1" of activeSheet to "Names in the Mail"
    set cellValue of range "D1" of activeSheet to "Email Addresses in the Mail"
    set cellValue of range "E1" of activeSheet to "Phone Numbers in the Mail"
    set cellValue of range "F1" of activeSheet to "Date Received"
    
    -- Get the list of text files in the folder
    set textFolderPath to (POSIX file desktopFolderPath) as alias -- Replace with your folder path
    set textFiles to every file of textFolderPath whose name extension is "txt"
    
    -- Loop through each text file and extract filtered information
    repeat with textFile in textFiles
        set filePath to (POSIX path of (textFile as alias))
        set fileContent to read textFile
        
        set senderName to ""
        set emailReference to ""
        set names to ""
        set emailAddresses to ""
        set phoneNumbers to ""
        set dateReceived to ""
        
        -- Extract the desired information from the fileContent
        -- Modify this section to extract the information based on your requirements
        
        -- Write the filtered information to the Excel worksheet
        set cellValue of range ("A" & rowIndex) of activeSheet to senderName
        set cellValue of range ("B" & rowIndex) of activeSheet to emailReference
        set cellValue of range ("C" & rowIndex) of activeSheet to names
        set cellValue of range ("D" & rowIndex) of activeSheet to emailAddresses
        set cellValue of range ("E" & rowIndex) of activeSheet to phoneNumbers
        set cellValue of range ("F" & rowIndex) of activeSheet to dateReceived
        
        set rowIndex to rowIndex + 1 -- Move to the next row for data
    end repeat
    
    save workbook as excelFilePath
    close newWorkbook saving no
end tell

display alert "Filtered information has been written to the Excel file."

结束告诉

-- 用于格式化接收时间的辅助函数 在 formatReceivedTime(receivedTime) 上 将 AppleScript 的文本项分隔符设置为 {“ ”, “/”, “:”} 将 receivedTimeItems 设置为 (receivedTime 作为字符串) 的文本项 将 formattedTime 设置为(receivedTimeItems 的第 1 项 & “-” & receivedTimeItems 的第 2 项 & “-” & receivedTimeItems 的第 3 项 & “_” & receivedTimeItems 的第 4 项 & receivedTimeItems 的第 5 项 & receivedTimeItems 的第 6 项) 将 AppleScript 的文本项分隔符设置为“” 返回 formattedTime 结束格式ReceivedTime

Excel 错误处理 Outlook AppleScript

评论


答: 暂无答案