【问题标题】:AppleScript to select the messages from Imap folder on Mail.appAppleScript 从 Mail.app 上的 Imap 文件夹中选择消息
【发布时间】:2018-04-29 15:14:50
【问题描述】:

我需要为 Mail.app 编写一个 Applescript,它将邮件的主题导出到 Excel 工作表中。

我在网上找到的可以做到这一点的衣柜代码如下:

    tell application "Microsoft Excel"
 set theSpamFile to make new workbook
 set theSheet to active sheet of theSpamFile
 set formula of range "B1" of theSheet to "Subject"
 set formula of range "A1" of theSheet to "From"
end tell
tell application "Mail"
 set theRow to 2
 get mailboxes
 set theMessages to messages of junk mailbox
 repeat with aMessage in theMessages
 my SetFrom(sender of aMessage, theRow, theSheet)
 my SetSubject(subject of aMessage, theRow, theSheet)
 set theRow to theRow + 1
 end repeat
end tell

on SetFrom(theSender, theRow, theSheet)
 tell application "Microsoft Excel"
 set theRange to "A" & theRow
 set formula of (range theRange) of theSheet to theSender
 end tell
end SetFrom

on SetSubject(theSubject, theRow, theSheet)
 tell application "Microsoft Excel"
 set theRange to "B" & theRow
 set formula of range theRange of theSheet to theSubject
 end tell
end SetSubject

这些代码适用于邮箱垃圾。

但我不知道如何操作代码来选择 Mail.app 中 Imap 帐户子文件夹中的邮件。

我在 Mail.app 中有几个 Imap 帐户。两个gmail账号,一个iCloud账号等等。我还在每个Imap账号下创建了折叠和子文件夹。

我想从子文件夹中导出未读邮件:它位于“Google/Supplier/SupplierUpdate”

我试图从

更改选择行
set theMessages to messages of junk mailbox

 set theMessages to messages of mailbox"[Google]/DobaSupplierUpdate/DobaCancellation"

但脚本编辑器一直显示以下消息:

Mail got an error: Can’t get mailbox "[Google]/DobaSupplierUpdate/DobaCancellation".

有什么帮助可以指引我正确的方向吗?

【问题讨论】:

    标签: excel email applescript directory imap


    【解决方案1】:

    试试这样的:

    -- set your email address here to find your account
    set targetAccount to first item of (every account whose user name is "xxx@googlemail.com")
    -- define the wanted subfolders here starting with deepest level
    set theMessages to every message of mailbox "SupplierUpdate" of mailbox "Supplier" of targetAccount whose read status is false
    

    最好, ShooTerKo / 汉堡

    【讨论】:

    • @Ivici 一个开放的问题就是一个开放的问题。如果您不想要答案,为什么不发布您的解决方案或只是删除问题?
    • 你的回答真的很棒!!!我不得不承认,即使你把代码给了我,我也感到不知所措。因为我是 AppleScript 的新手。所以我多次尝试用关联代码行替换它们。最后我明白了。非常感谢您的帮助。这将更快地改善我的日常工作。最佳
    • 我如何从电子邮件的“主题”中提取特定部分?例如,主题都是这种类型:“来自 UNFI 的订单 1422474 的跟踪信息”。我需要的唯一部分就是数字部分“1422474”。在将它们输入 Excel 电子表格之前,如何从主题中提取它?
    • 我建议在 SO 上搜索解决方案或提出新问题。将这些 cmets 用作线程并不好。搜索“从字符串中提取数字”之类的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-08
    • 2014-03-20
    • 1970-01-01
    • 2010-10-10
    • 1970-01-01
    • 2016-08-30
    • 2012-10-29
    相关资源
    最近更新 更多