Applescript commands mail
AppleScript can be used to automate various tasks in Mail.app, including sending and receiving emails, managing contacts, and more. Here are some common AppleScript commands for Mail:
Sending an Email
tell application "Mail"
: Opens the Mail applicationset theMessage to make new outgoing message with properties {subject:"My Subject", content:"My Message"}
: Creates a new outgoing message with a subject and contentset theRecipient to "[email protected]"
: Sets the recipient of the emailsend theMessage
: Sends the email
Example:
tell application "Mail"
set theMessage to make new outgoing message with properties {subject:"My Subject", content:"My Message"}
set theRecipient to "[email protected]"
send theMessage
end tell
Receiving an Email
tell application "Mail"
: Opens the Mail applicationset theAccount to first account whose name is "Your Account Name"
: Selects the account to receive emails fromset theFilter to make new filter with properties {name:"My Filter", criteria:"from contains \"[email protected]\""}
: Creates a new filter to receive emails from a specific senderset theMessage to first message of theFilter
: Retrieves the first message that matches the filter criteriaset theContent to content of theMessage
: Retrieves the content of the message
Example:
tell application "Mail"
set theAccount to first account whose name is "Your Account Name"
set theFilter to make new filter with properties {name:"My Filter", criteria:"from contains \"[email protected]\""}
set theMessage to first message of theFilter
set theContent to content of theMessage
end tell
Managing Contacts
tell application "Mail"
: Opens the Mail applicationset theContact to make new contact with properties {name:"John Doe", email:"[email protected]", phone:"123-456-7890"}
: Creates a new contact with name, email, and phone numberset theContact to first contact whose name is "John Doe"
: Retrieves the contact with the specified nameset theEmails to emails of theContact
: Retrieves the email addresses associated with the contact
Example:
tell application "Mail"
set theContact to make new contact with properties {name:"John Doe", email:"[email protected]", phone:"123-456-7890"}
set theContact to first contact whose name is "John Doe"
set theEmails to emails of theContact
end tell
Other Commands
tell application "Mail"
: Opens the Mail applicationget inbox
: Retrieves the inbox mailboxget sent mailbox
: Retrieves the sent mailboxget drafts mailbox
: Retrieves the drafts mailboxget trash mailbox
: Retrieves the trash mailboxget junk mailbox
: Retrieves the junk mailbox
Example:
tell application "Mail"
set theInbox to inbox
set theSent to sent mailbox
set theDrafts to drafts mailbox
set theTrash to trash mailbox
set theJunk to junk mailbox
end tell
These are just a few examples of the many AppleScript commands available for Mail. You can use these commands to automate various tasks, such as sending emails, managing contacts, and more.