Select 一种带通配符的电子邮件发件人

Select a type of sender for email with wildcard

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

有没有办法自动 select 包含 "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 中帐户的发件人地址存储在 sender addresses 属性 中的一个 account 中。所以,从技术上讲,你想要的是 get account whose email addresses ends with "@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

您可能还会发现查看每个帐户的属性很有用,方法如下:

tell application "Mail"
    --or “account 1”, “account 3”, etc., up to the number of accounts
    get properties of account 2
end tell

如果您 运行 然后查看 结果 窗格,您将看到所有属性,包括 email addresses 属性.如果您的脚本没有按照您的预期执行,post 不仅是脚本,还有您正在查看的 属性 的值,在本例中为 email addresses 属性。您可能希望使用带有假 example.com、example.org 和 example.net 电子邮件地址的测试计算机,以免将真实电子邮件地址暴露给收割者。

您可能还会发现从头开始构建脚本更容易。例如,在这种情况下,您可能希望编写一个脚本,从硬编码的发件人处发送一封硬编码的电子邮件。只有当脚本的那个方面起作用时,您才会想要添加关于搜索动态发件人的皱纹。这将通过使每个任务更小来简化您的编程过程,并且还将使代码误入歧途的地方更加明显。