获取所选邮箱的电子邮件地址

时间:2015-08-14 12:22:19

标签: macos applescript

我正在尝试接收邮件中活动帐户的邮件地址。

到目前为止,我做了以下

tell application "Mail"
    set selected to selected mailboxes of message viewer 1
end tell

tell application "Mail"
    email addresses of every account
end tell

但不知怎的,我不能做像

那样的事情
tell application "Mail"
    set selectedMailboxes to selection
    set theAccount to account of selection
    return theAccount
end tell

The Last applescript不起作用。如何在message vieview 1

中检索邮箱帐户

1 个答案:

答案 0 :(得分:1)

试试这个

tell application "Mail"
    try
        set selectedMailbox to item 1 of (get selected mailboxes of message viewer 1)
        set mailAddresses to email addresses of account of selectedMailbox
    on error
        display dialog "No Mailbox selected"
    end try
end tell

由于帐户可以有多个邮件地址,因此即使只有一个地址,变量mailAddresses的类也是一个列表。

使用索引号(从1开始)获取所需的地址

set myAddress to item 1 of mailAddresses

set myAddress to second item of mailAddresses