使用 AppleScript 打开电子邮件中发送的链接

时间:2021-06-09 18:33:57

标签: applescript email-processing

我正在尝试自动化打开通过电子邮件发送的特定链接的过程。

电子邮件中有多个链接,其中包括一个取消订阅服务的链接,因此打开正确的链接而不是所有链接都很重要。

流程如下:

  1. 电子邮件进入并触发规则
  2. 规则查找两个参数:来自地址的电子邮件和电子邮件正文中的关键短语(不是链接)
  3. 规则将电子邮件移动到特定邮箱,然后触发 AppleScript
  4. AppleScript 搜索特定 URL 的开头并在浏览器中打开它(我白天在方便时手动查看打开的浏览器标签)
  5. 电子邮件标记为已读

这是我无法正常工作的:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        repeat with eachMessage in theMessages
            tell application "Mail" to set t to paragraphs of the content of eachMessage
            repeat with i in t
                if i starts with "http://www.website.com/specific/link" then tell application "Safari" to open location i
            end repeat
        end repeat
    end perform mail action with messages
end using terms from

关于我可以做些什么来使这个过程起作用的任何建议?

1 个答案:

答案 0 :(得分:0)

您应该获得 AppleScript 段落而不是 Mail.app 段落:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        repeat with eachMessage in theMessages
            tell application "Mail" to set t to (content of eachMessage) as string -- EDITED
            set t to paragraphs of t -- ADDED
            repeat with i in t
                if i starts with "https://stackoverflow.com/questions/67909907/open-links-sent-in-email-using-applescript" then openLocation(i)
            end repeat
        end repeat
    end perform mail action with messages
end using terms from

on openLocation(theURL)
    tell application "Safari" to open location theURL
end openLocation
相关问题