0

需要将联系人中的电子邮件地址转换为 Mail 中的收件人。

tell application "Contacts"
    set sendTo to every person's email 1
end tell

tell application "Mail"
    set mesg to make new outgoing message
    set recipient of mesg to sendTo -- Need to convert here.
    set subject of mesg to "A title"
    set content of mesg to "A body"
    send mesg
end tell
4

1 回答 1

1

您的代码中有几个问题...

  1. 当您收到“每个人的电子邮件 1”时,您会收到一份参考列表,而不是电子邮件地址列表。要从参考中获取实际的电子邮件地址,您将获得它的“价值”。

  2. sendTo 将是一个列表,因此您必须遍历列表并在邮件中一次添加一个地址。

  3. 有不同类型的收件人。您需要使用“收件人”。

尝试这个:

tell application "Contacts"
    set sendToList to value of every person's email 1
end tell

set emailSender to "me@me.com"
set theSubject to "The subject of the mail"
set theContent to "message body"
tell application "Mail"
    set mesg to make new outgoing message with properties {sender:emailSender, subject:theSubject, content:theContent, visible:true}
    tell mesg
        repeat with i from 1 to count of sendToList
            set thisEmail to item i of sendToList
            if thisEmail is not missing value then
                make new to recipient at end of to recipients with properties {address:thisEmail}
            end if
        end repeat
        --send
    end tell
end tell
于 2015-03-29T05:34:48.683 回答