【问题标题】:applescript & Mac Mail - extract content from mail body to an excel spreadsheet - not all content extractsapplescript & Mac Mail - 将邮件正文中的内容提取到 Excel 电子表格中 - 并非所有内容都提取
【发布时间】:2020-07-02 03:00:07
【问题描述】:

我正在尝试使用 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 执行此操作...有人可以帮忙吗?我是新语言!

约翰

【问题讨论】:

    标签: excel macos applescript


    【解决方案1】:

    我认为您的问题只是从邮件中提取(而不是发送到 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 方面的帮助,请告诉我。

    【讨论】:

      猜你喜欢
      • 2015-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 2011-12-30
      • 1970-01-01
      • 2016-04-20
      相关资源
      最近更新 更多