问题
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 "mark@sender.com"
make new to recipient at end of to recipients with properties {address:"recipient@mac.com"}
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:'

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.
回答1:
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:"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
回答2:
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 <hank@sender.com>"
回答3:
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
来源:https://stackoverflow.com/questions/9353486/incorrect-sender-when-sending-email-via-applescript