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

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

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

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

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.