【问题标题】:Use Applescript to set the "Reply-To" address使用 Applescript 设置“回复”地址
【发布时间】:2013-08-08 00:31:18
【问题描述】:

我有一个注册域,我使用hushmail 作为邮件提供商。我想从 Mail.app 发送电子邮件,就好像它们是从我的域发送的一样。出于安全原因(垃圾邮件),Hushmail SMTP 服务器不允许我使用与帐户名不同的“发件人”地址。

我找到了一种让 Apple 邮件始终使用默认值填充回复邮件的方法,这里是:http://email.about.com/od/macosxmailtips/qt/etalwaysreplyto.htm,但这对我来说太激进了,因为我的邮件客户端中有多个邮件帐户。

在 Mail.app 中,我可以手动设置“回复”字段,但 Mail.app 中没有设置根据我选择的邮箱自动填充。

到目前为止,我有一个 AppleScript 可以在所选邮件上创建回复:

tell application "Mail"
    set theSelection to selection
    if theSelection is {} then return
    activate

    repeat with thisMessage in theSelection
        set theOutgoingMessage to reply thisMessage with opening window


        # Wait for Mail.app to create the reply window
        repeat until exists (window 1 whose name = "Re: " & subject of thisMessage)
        end repeat
        delay 0.1

        #
        # Here I want to set the reply-to address here based on the 
        # selected mailbox, or the "from" address of 
        # the current mail.
        #

        #
        # The I need to restore the cursor to the body of the mail 
        # (if cursor was moved)
        #
    end repeat
end tell

我查看了 AppleScript 字典(文件 -> 打开字典 -> Mail.app -> 消息 -> 消息 -> 回复),这似乎是我应该能够设置的属性,但是当我会这样做:

tell theOutgoingMessage
make new recipient at end of reply to with properties {address:"myreplyto@example.com"}

弹出一条错误消息,提示“邮件出错:无法得到外发邮件 id 65 的回复。”

我也试过

tell theOutgoingMessage
set reply to to "myreplyto@example.com"

但这会弹出一条错误消息“邮件出错:无法将外发消息 id 69 的回复设置为“myreplyto@example.com”。

如何设置刚刚创建的回复邮件的回复属性?

【问题讨论】:

  • 在字典中查找显示此...回复(文本,r/o)。 r/o 意味着这是一个只读属性,因此您将无法以编程方式设置它。您只能以编程方式阅读它。因此,您必须使用 ui 元素脚本技术。

标签: macos email applescript


【解决方案1】:

正如我在您帖子的 cmets 中提到的,您不能以编程方式设置回复地址,因为它是只读属性。因此,您需要编写此解决方案的 ui 脚本。

ui 脚本的问题在于它不是一门精确的科学。如果 Apple 更改了 ui 元素的位置,那么您的脚本将停止工作。例如,我有 Mail.app v6.5,可以使用“窗口 1 的滚动区域 1 的文本字段 1”来引用回复字段。在其他版本的 Mail.app 中可能会有所不同(并且可能是)。

无论如何,在 Mail.app 的 v6.5 中,这将使用 ui 脚本执行您想要的操作。

tell application "Mail"
    set theSelection to selection
    if theSelection is {} then return
    activate

    repeat with thisMessage in theSelection
        set replyToAddress to item 1 of (get email addresses of account of mailbox of thisMessage)
        set replyToWindowName to subject of thisMessage
        if replyToWindowName does not start with "Re:" then set replyToWindowName to "Re: " & replyToWindowName

        -- open the reply message
        set theOutgoingMessage to reply thisMessage with opening window

        -- Wait for Mail.app to create the reply window
        repeat until exists (window 1 whose name is replyToWindowName)
            delay 0.2
        end repeat

        -- make sure the reply-to field is showing
        my openReplyToField()

        -- set the reply-to address here based on the selected mailbox
        my setValueOfReplyToField(replyToAddress)
    end repeat
end tell

on openReplyToField()
    tell application "System Events"
        tell process "Mail"
            -- figure out if the reply-to text field is visible
            set staticText to value of every static text of window 1
            if staticText contains "Reply To:" then return

            -- the reply-to field is not visible so we click the menu item
            set viewMenu to menu 1 of menu bar item "View" of menu bar 1
            set replyToMenuItem to first menu item of viewMenu whose name contains "Reply-To"
            click replyToMenuItem
        end tell
    end tell
end openReplyToField

on setValueOfReplyToField(theValue)
    tell application "System Events"
        tell process "Mail"
            set replyToField to text field 1 of scroll area 1 of window 1
            set value of replyToField to theValue
        end tell
    end tell
end setValueOfReplyToField

【讨论】:

  • 非常有前途。我有 Mail 6.3,脚本不能开箱即用,但我正在尝试结合想法。您的脚本有一些很好的指示。
【解决方案2】:

试试这是否可行:

make new recipient at end of to recipients with properties {address:"myreplyto@example.com"}

【讨论】:

  • 这并不能解决问题。它会在“收件人”:字段中添加收件人,但不会在“回复”字段中添加收件人。为清楚起见:当您选择查看 -> 回复地址字段时,回复字段变为可见。
  • 操作,你是对的,我现在明白了。从 Mail AppleScript 字典中,传出消息类似乎不支持对属性的回复。我认为唯一的解决方案是编写 gui 脚本,在脚本末尾添加以下代码:告诉应用程序“系统事件”设置应用程序进程“邮件”前窗口滚动区域 1 的(文本字段 1)的值“myreplyto@example.com”结束告诉
猜你喜欢
  • 2011-05-09
  • 2013-12-31
  • 2011-01-05
  • 2020-11-04
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
  • 2010-12-07
  • 2020-12-19
相关资源
最近更新 更多