Mail - Specifying account to send email from

I’m using mail and trying to send a message from a specific account that isn’t my default account. It creates the mail but from my default account even though i’m specifying the account I want it to send it from.

Any help would be appreciated.

i want it to send the email from the account called “gmail”

set theAccount to "gmail"
set the_mailto to "email@mail.com"
tell application "Mail"
	activate
	set newMessage to make new outgoing message with properties {account:theAccount, address:the_mailto}
	tell newMessage
		set visible to true
		make new to recipient at end of to recipients with properties {address:the_mailto}
	end tell
end tell

Hi,

the proper property for the sender account is sender, not account

thanks for the direction:

working version:

set theAccount to "put-your-account-email-here@mail.com"
set the_mailto to "email@mail.com"
tell application "Mail"
	activate
	set newMessage to make new outgoing message with properties {sender:theAccount, address:the_mailto}
	tell newMessage
		set visible to true
		make new to recipient at end of to recipients with properties {address:the_mailto}
	end tell
end tell

thanks for the help. Greatly appreciate it.

How do I set the sender of an outgoing mail to any sender beyond the first sender?
Application “Mail” fails the following applescript, and only returns the default Account.

set theAccount to "target account@mail.com"
tell application "Mail" to set newMessage to make new outgoing message with properties {sender:theAccount}

“theAccount” variable has to set to an email account that is configured within mail. “target account@mail.com” will always return the default email account.

If you change “target account@mail.com” to an email address configured within the Mail app then it will compose the email using that account which i have tested and works in 10.14.1

Any idea how to get this to work in Outlook 16.44+

The Mail.app recognizes different senders with different user names of accounts, and the user name of each account is on my Mac for example, the email address of the account.

So, in the example bellow 2 first messages will be recognized as sended by the same account, because they use the same Gmail address, (case of letters does not make a difference). The 3rd message will be recognized as sended by different account (because it use different Gmail address from two first messages).

So, the number of really different accounts of the computer’s current user is not equal to the number of all Mail.app accounts, but to the number of real user’s mailboxes on the Internet (known to your Mail.app, of course, thanks to adding them in the settings):

set the_mailto to "kniazidis.rompert@gmail.com" -- to test, I send the messages to me
set theSubject to ""
set theContent to ""

tell application "Mail"
	set userNames to user name of every account
	-->  {"KNIAZIDIS.ROMPERT@gmail.com","kniazidis.rompert@gmail.com","robert2.kniazidis2@gmail.com"}
	activate
	repeat with userName in userNames
		set newMessage to make new outgoing message with properties {sender:userName, subject:theSubject, content:theContent, visible:false}
		tell newMessage to make new to recipient at end of to recipients with properties {address:the_mailto}
		send newMessage
	end repeat
end tell

When I try to use the following script appearing above :

set theAccount to "victor@thelawfirm.eu"
set the_mailto to "xxx@icloud.com"
tell application "Mail"
	activate
	set newMessage to make new outgoing message with properties {sender:theAccount, address:the_mailto}
	tell newMessage
		set visible to true
		make new to recipient at end of to recipients with properties {address:the_mailto}
	end tell
end tell

I get the following error message:

Although the email listed is not my real email address in the script the correct email is being used.

Any help would be gratefully received.

macOS 13.1

Model: MBA 2022, M2
AppleScript: 2.8
Browser: Safari 605.1.15
Operating System: macOS 12

Try this

set theAccount to "username@domain.com"
set the_mailto to "xxx@icloud.com"
tell application "Mail"
	set newMessage to make new outgoing message with properties {sender:theAccount}
	tell newMessage
		set newRecipient to make new to recipient with properties {address:the_mailto}
	end tell
end tell

Here is a version that checks if theAccount exists in MAIL

set theAccount to "username@domain.com"
set the_mailto to "xxx@icloud.com"
set emailAddresses to {}
tell application "Mail"
	set myAccounts to accounts
	repeat with anAccount in myAccounts
		set emailAddresses to emailAddresses & email addresses of anAccount
	end repeat
	if theAccount is not in emailAddresses then return
	set newMessage to make new outgoing message with properties {sender:theAccount}
	tell newMessage
		set newRecipient to make new to recipient with properties {address:the_mailto}
	end tell
end tell

Thank you very much for the information.

The script now working.

Model: MBA 2022, M2
AppleScript: 2.8
Browser: Safari 605.1.15
Operating System: macOS 12