Applescript 使用通配符选择电子邮件的发件人类型

Applescript 使用通配符选择电子邮件的发件人类型,applescript,Applescript,我想用applescript发送一封电子邮件。此脚本将在一些计算机上使用,电子邮件应通过电子邮件地址中包含mynetwork.com的特定类型的帐户发送 有没有办法自动选择包含my network.com的计算机电子邮件帐户?显然,通配符*不起作用,请参见下面的代码 property faxboxEmail : {"fax@opilbox.com"} property theNumber : "" property theContent : "" property theSender :

我想用applescript发送一封电子邮件。此脚本将在一些计算机上使用,电子邮件应通过电子邮件地址中包含mynetwork.com的特定类型的帐户发送

有没有办法自动选择包含my network.com的计算机电子邮件帐户?显然,通配符*不起作用,请参见下面的代码

 property faxboxEmail : {"fax@opilbox.com"}
 property theNumber : ""
 property theContent : ""
 property theSender : "*@mynetwork.com"

tell application "Mail"
  set newMessage to make new outgoing message with properties {visible:true,      subject:theNumber, content:theContent, sender:theSender}
       tell newMessage
  make new to recipient with properties {address:faxboxEmail}
       end tell
end tell

Mac OS X Mail中帐户的发件人地址存储在帐户的“发件人地址”属性中。所以,从技术上讲,你想要的是像get这样的账户,其电子邮件地址以@mynetwork.com结尾。然而,email addresses属性是一个简单的列表,AppleScript没有像那样对列表进行动态搜索

然而,任何个人电脑上的帐户数量都应该相当少,因此循环使用它们应该不是问题

property faxboxEmail : {"fax@opilbox.com"}
property theNumber : "Nine"
property theContent : "Hello, World"

set foundAddress to false

tell application "Mail"
    repeat with potentialSender in accounts
        tell potentialSender
            repeat with potentialAddress in email addresses as list
                if potentialAddress ends with "@mynetwork.com" then
                    set foundAddress to true
                    exit repeat
                end if
            end repeat
        end tell
        if foundAddress then
            exit repeat
        end if
    end repeat

    if foundAddress then
        set senderName to full name of potentialSender
        set senderAddress to senderName & " <" & potentialAddress & ">"
        set newMessage to make new outgoing message with properties {visible:true, subject:theNumber, content:theContent, sender:senderAddress}
        tell newMessage
            make new to recipient with properties {address:faxboxEmail}
        end tell
    end if
end tell
如果运行该命令,然后查看结果窗格,您将看到所有属性,包括电子邮件地址属性。如果你的脚本没有达到你期望的效果,那么不仅要发布脚本,还要发布你正在查看的属性的值,在本例中是email addresses属性。您可能希望使用一台带有假的example.com、example.org和example.net电子邮件地址的测试计算机,以免向收割机公开真实的电子邮件地址


您还可能发现从头开始构建脚本更容易。例如,在本例中,您可能希望编写一个脚本,从硬编码发件人发送硬编码电子邮件。只有在脚本的这一方面起作用后,您才会希望添加搜索动态发件人的技巧。这将使每个任务更小,从而简化您的编程过程,并使代码误入歧途的地方更加明显。

谢谢您的回答,但它似乎不起作用。如果我使用ends with.com,则可以,但如果我使用ends with.me,则找不到任何帐户,并且由于未定义foundAddress而出现错误。我的账户以.com、.ch和.meMore结尾,我的账户以.com结尾emailx@blah.com, emaily@blo.ch, emailz@bla.me我只想选择@blo.ch account。我已经修改了示例,以包含foundAddress变量的初始化,这样当没有匹配的地址时,if/then不会失败。我还添加了一些关于检查每个帐户的值的建议。实际上,通过查看属性的值,我发现您的脚本工作得很好,但它是命令set newMessage,用于生成具有属性{visible:true,subject:theNumber,sender:senderAddress,content:theContent}的新传出消息这无法正常工作,并且未正确考虑发件人地址。知道为什么吗?啊,知道。发件人地址的格式非常具体。它必须包括发件人的姓名以及地址。我修改了脚本以考虑到这一点。
tell application "Mail"
    --or “account 1”, “account 3”, etc., up to the number of accounts
    get properties of account 2
end tell