我需要将电子邮件地址转换为收件人

时间:2015-03-28 19:51:03

标签: applescript apple-mail

需要将联系人中的电子邮件地址转换为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

1 个答案:

答案 0 :(得分:1)

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

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

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

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

  4. 试试这个:

    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