choosing mail account in applescript - macos

I'd like to send a mail using a Mac Automator action. I prepared the following mail script:
set recipientName to "<recipient>"
set recipientAddress to "<recipient mail address>"
set theSubject to "<mail subject>"
set textBody to "<text>"
tell application "Mail"
set theMessage to make new outgoing message with properties {subject:theSubject, content:textBody, visible:true}
--set recipient
tell theMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}
--send the message
send
end tell
end tell
now when I send this it uses the Account that is basically currently selected (highlighted) in the Mail App.
Is there any way to choose a specific account?

You need to set the sender of theMessage to a valid address of one of your accounts.
e.g.
set recipientName to "<recipient>"
set recipientAddress to "<recipient mail address>"
set theSubject to "<mail subject>"
set textBody to "<text>"
set theSender to "dragon5689#stackoverflow.com" -- your valid account email here
tell application "Mail"
set theMessage to make new outgoing message with properties {subject:theSubject, content:textBody, visible:true, sender:theSender}
tell theMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}
send
end tell
end tell

Related

messages - AppleScript send image on macOS 12

So I have this AppleScript
set filePath to (path to desktop as text) & "photo.png"
tell application "Messages"
set targetService to 1st account whose service type = iMessage
set targetBuddy to participant "+18005555555" of targetService
send file filePath to targetBuddy
end tell
worked before but in macOS 12 it looks like it's working (see the progress bar) but eventually timesout and states it can't be sent.
Is there an update to sending this?

How to set sender in Outlook POP account using AppleScript?

This script selects my main account and the signature related to it.
tell application "Microsoft Outlook"
set theContent to "Mail Content etc."
set theMessage to make new outgoing message with properties {subject:(("Month ") & (do shell script "date '+%m'")), content:theContent}
make new recipient with properties {email address:{address:"to#mail.com"}} at end of to recipients of theMessage
make new recipient with properties {email address:{address:"to#mail.com"}} at end of cc recipients of theMessage
open theMessage
end tell
I would like to add a line that picks one of several POP accounts to send from.
Ideally the resulting mail has the signature stored under that address.

Select mailbox for Microsoft Outlook when using Applescript

I'm using Applescript to automatically draft and send emails in Microsoft Outlook. While everything is working as expected to send emails from my own account, I want to adjust the script to send emails from a different account that I have access to in Outlook. I've found this post, but the approach shown there generates an error for me.
https://macscripter.net/viewtopic.php?pid=185222#p185222
How can I adjust the script below to select the correct mailbox to send my email from? When I use the script below, the following error is generated when I attempt to save it.
Syntax Error
Expected class name but found identified
I've Google this error message, but haven't been able to find anything relevant to my task of changing the account the email is sent from.
set theAccount to the first exchange account whose name is "second.account#company.com"
set recipientAddress to "first.last#company.com"
set theSubject to "This is only a test"
set theContent to "<html><body><p>This is only a test.</p></body></html>"
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {account:theAccount, subject:theSubject, content:theContent}
tell newMessage
make new recipient at newMessage with properties {email address:{address:recipientAddress}}
end tell
save in drafts
end tell

MacOS. How to programmatically check a new SMS message?

I want to periodically programmatically check whether a new SMS message has arrived from a specific sender. If it came, then I want to copy text the text to the clipboard.
using terms from application "Messages"
on message received theMessage from theBuddy for theChat with eventDescription
set the clipboard to theMessage
end message received
end using terms from

How to add an attachment to an email reply with AppleScript

The code below allows me to create an email reply:
tell application "Mail"
set theAttachmentFile to "path"
set theMessages to the selected messages of the front message viewer
set theMessage to first item of theMessages
set theOutgoingMessage to reply theMessage with opening window and
reply to all
end tell
in this situation I'm not able to add an attachment file to the replay front message. In what way can i do that? Is it possible?
Thanks!

Resources