Applecript& Mac Mail - 将邮件正文中的内容提取到Excel电子表格 - 而非所有内容摘录

时间:2018-05-03 09:46:42

标签: applescript applescript-excel

使用Applescript我正在尝试将Mac Mail中特定文件夹中所有电子邮件的正文内容提取到Excel电子表格中。我可以使用下面的代码执行此操作,但由于某些原因并非所有正文内容(只是文本)被提取,它会在关键点切断,就在抓取目标电子邮件地址之前或之中,典型的!

tell application "Microsoft Excel"

    set LinkRemoval to make new workbook

    set theSheet to active sheet of LinkRemoval

    set formula of range "A1" of theSheet to "Date"

end tell





tell application "Mail"

    set theRow to 2

    set theAccount to "Exchange"

    get account theAccount

    set theMessages to messages of mailbox "Inbox/Target Folder" of account "Exchange"

    repeat with aMessage in theMessages

        my SetMessage(content of aMessage, theRow, theSheet)

        set theRow to theRow + 1

    end repeat

end tell



on SetMessage(theMessage, theRow, theSheet)

    tell application "Microsoft Excel"

        set theRange to "A" & theRow

        set formula of range theRange of theSheet to theMessage

    end tell

end SetMessage

我被告知将其解压缩为CSV文件可能有所帮助,但我不知道如何使用Applescript执行此操作...有人可以帮忙吗?我是新语言!

约翰

1 个答案:

答案 0 :(得分:0)

我认为你的问题只是从Mail中提取(而不是发送到Excel)。所以在这里,这将从一系列消息中提取电子邮件内容。您需要声明帐户和邮箱的变量。

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

on ParseEmailMessages(theMsg)
    tell application "Mail"
        set subj to subject of theMsg
        set DateName to date received of theMsg
        set SenderN to sender of theMsg
        set SenderName to extract name from sender of theMsg
        set senderAddress to extract address from sender of theMsg
        set BodyMessage to content of theMsg
        set IDName to id of theMsg as string
        try
            set RecipientsAddress to address of recipients of theMsg
            set RecipientsName to name of recipients of theMsg
        on error
            set RecipientsN to ""
        end try
        set AttachmentsV to mail attachment of theMsg
    end tell
    set Msg to {subj:subj, RecipientsName:RecipientsName, RecipientsAddress:RecipientsAddress, DateName:DateName, SenderN:SenderN, senderAddress:senderAddress, SenderName:SenderName, BodyMessage:BodyMessage, IDName:IDName, AttachmentsV:AttachmentsV}
    return Msg
end ParseEmailMessages


on run
    tell application "Mail"
        set theMessages to messages of the mailbox TheMailbox of TheAccount
        repeat with i from 1 to count of theMessages
            set theMsg to item i of theMessages
            set Msg to ParseEmailMessages(theMsg)
        end repeat
    end tell
end run

如果您需要Excel帮助,请告诉我。

相关问题