5
votes

The Applescript below is in the form that I have used for a number of years. And is basically a well known method of sending emails using 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 "[email protected]"
        make new to recipient at end of to recipients with properties {address:"[email protected]"}
        send
    end tell
end tell

What I just noticed today is the 'sender' email set in the script, may not be the one Mail.app uses if its account mail box is not selected. A random one will be used if the main inbox is selected or if an individual mailbox is selected then an address from it's account will be used.

I think this is because in the Mail preferences, under Composing. There is a setting to 'Send new messages from:'


enter image description here


You cannot select 'NO'. The only options are 'Account of selected mailbox' or one of the email addresses that are in the combo box drop down.

I must admit I do not know if this was been happening before I went to Lion.

Does anyone know of a fix for this, or if this is a known bug??.

Thanks.

4

4 Answers

15
votes

this worked for me just now, hope it helps:

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:"[email protected]"}
    set sender to "Name Surname <[email protected]>"
    set subject to "Message Subject"
    set content to "Message Text"
  end tell
end tell
2
votes

I don't know where I got this from, but the sender needs a particular format. It should be:

full name <email_address>

You look in Mail's account preferences, and use the "Full Name" and "email address" fields from one of the accounts... but put it in the form I showed. I just checked and this format works for me. As such I use this in my applescripts...

set emailSender to "FirstName LastName <[email protected]>"
0
votes

If you are looking for a script that will send an email, this one should work.

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
0
votes

To figure out what emails you have available this can help:

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