我需要将电子邮件地址转换为收件人
I need to convert an email address to a recipient
需要将联系人中的电子邮件地址转换为邮件中的收件人。
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
你的代码有几个问题...
当您获得 "every person's email 1" 时,您将获得参考列表,而不是电子邮件地址列表。要从参考中获取实际电子邮件地址,您需要获取其 "value".
sendTo 将是一个列表,因此您必须遍历该列表并在邮件中一次添加一个地址。
有不同类型的收件人。您需要使用 "to recipient".
试试这个:
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
需要将联系人中的电子邮件地址转换为邮件中的收件人。
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
你的代码有几个问题...
当您获得 "every person's email 1" 时,您将获得参考列表,而不是电子邮件地址列表。要从参考中获取实际电子邮件地址,您需要获取其 "value".
sendTo 将是一个列表,因此您必须遍历该列表并在邮件中一次添加一个地址。
有不同类型的收件人。您需要使用 "to recipient".
试试这个:
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