通过Applescript发送电子邮件时发件人不正确

时间:2012-02-19 21:37:30

标签: applescript

下面的Applescript采用了我多年来使用过的形式。并且基本上是使用Applescript发送电子邮件的众所周知的方法。

 tell application "Mail"
    set newMessage to make new outgoing message with properties {subject:"IP Address", content:"Your IP Address Is: 86.195.132.134"}
    tell newMessage
        set visible to false
        set sender to "mark@sender.com"
        make new to recipient at end of to recipients with properties {address:"recipient@mac.com"}
        send
    end tell
end tell

我今天刚注意到的是脚本中设置的'发件人'电子邮件,可能不是Mail.app 如果未选中其帐户邮箱,则使用。如果选择了主收件箱,或者如果选择了单个邮箱,则将使用随机邮件,然后将使用其帐户中的地址。

我认为这是因为在“邮件”偏好设置中的“撰写”下。有一个设置为'发送新邮件:'


enter image description here


您无法选择“否”。唯一的选项是“所选邮箱的帐户”或组合框中的一个电子邮件地址下拉列表。

我必须承认,在我去狮子会之前,我不知道这是否发生过。

有没有人知道修复此问题,或者这是否已知错误?

感谢。

4 个答案:

答案 0 :(得分:12)

这对我来说很有用,希望有所帮助:

tell application "Mail"
  set theOutMessage to make new outgoing message with properties {visible:true}
  tell theOutMessage
    make new to recipient at end of to recipients with properties {address:"first@mail.com"}
    set sender to "Name Surname <name.surname@mail.com>"
    set subject to "Message Subject"
    set content to "Message Text"
  end tell
end tell

答案 1 :(得分:1)

我不知道从哪里得到这个,但发件人需要特定的格式。它应该是:

full name <email_address>

您查看Mail的帐户首选项,并使用其中一个帐户中的“全名”和“电子邮件地址”字段...但是将其放在我显示的表单中。我刚检查过,这种格式适合我。因此我在我的Applecripts中使用它......

set emailSender to "FirstName LastName <hank@sender.com>"

答案 2 :(得分:0)

如果您正在寻找一个可以发送电子邮件的脚本,那么这个应该有用。

set theRecipient to text returned of (display dialog "Who would you like to email" default answer "" buttons {"Cancel", "Ok"} default button 2)
set theSubject to text returned of (display dialog "What is the subject" default answer "" buttons {"Cancel", "Ok"} default button 2)
set theContent to text returned of (display dialog "What would you like to say" default answer "" buttons {"Cancel", "Ok"} default button 2)
tell application "Mail"
    set theNewMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
    tell theNewMessage
        make new to recipient at end of to recipients with properties {address:theRecipient}
        send
        tell application "Mail"
            activate
        end tell
    end tell
end tell

答案 3 :(得分:0)

要弄清楚您可以使用哪些电子邮件,这会有所帮助:

tell application "Mail"
    set emailList to []
    repeat with theAccount in (every account where enabled is true)
        tell theAccount
            set accountEmails to email addresses
            set accountFullName to full name
            repeat with accountEmail in accountEmails
                set fullEmail to accountFullName & " <" & accountEmail & ">"
                set emailList to emailList & fullEmail
            end repeat
        end tell
    end repeat
end tell

get emailList