Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 使用Applescript设置;答复「;地址_Macos_Email_Applescript - Fatal编程技术网

Macos 使用Applescript设置;答复「;地址

Macos 使用Applescript设置;答复「;地址,macos,email,applescript,Macos,Email,Applescript,我有一个注册域,我使用hushmail作为邮件提供商。我想从Mail.app发送电子邮件,就像它们是从我的域发送的一样。出于安全原因(垃圾邮件),Hushmail SMTP服务器不允许我使用与帐户名不同的“发件人”地址 我找到了一种方法,让Apple mail在回复邮件时始终使用默认设置:但这对我来说太过分了,因为我的邮件客户端中有多个邮件帐户 在Mail.app中,我可以手动设置“回复到”字段,但在Mail.app中没有根据我选择的邮箱自动填充的设置 到目前为止,我有一个AppleScript

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

我找到了一种方法,让Apple mail在回复邮件时始终使用默认设置:但这对我来说太过分了,因为我的邮件客户端中有多个邮件帐户

在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字典(File->Open Dictionary->Mail.app->Message->Message->reply to),这似乎是我应该能够设置的属性,但当我执行以下操作时:

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“

如何设置我刚刚创建的回复邮件的“回复到”属性?

如果可以,请尝试:

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

正如我在你文章的评论中提到的,你不能以编程方式设置回复地址,因为它是一个只读属性。因此你需要为这个解决方案编写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

这并不能解决问题。它会在“收件人”字段中添加收件人,但不会在“回复收件人”字段中添加收件人"字段。为清晰起见:当您选择查看->回复地址字段时,回复字段将可见。Ops,我现在明白了,您是对的。从Mail AppleScript dictionary,传出消息类似乎不支持回复属性。我认为唯一的解决方案是编写gui脚本,在脚本末尾添加以下代码:告诉应用程序“系统事件”应用程序进程“邮件”至前窗口滚动区域1的(文本字段1)设置值myreplyto@example.com“在字典中查找的结尾显示……回复(文本,r/o)。r/o意味着这是一个只读属性,因此您无法以编程方式设置它。您只能以编程方式读取它。因此,您必须使用ui元素脚本技术来完成。非常有希望。我有Mail 6.3,脚本不能开箱即用,但我正在尝试结合各种想法。您的脚本有一些很棒的指针。