Apple - AppleScript/Automate Mail Tasks
This is certainly possible with AppleScript. Here are some resources and snippets to help you craft your ideal script.
The final AppleScript combines the content of any selected e-mails and prepares an outgoing e-mail ready for sending. You can embed this AppleScript within an Automator workflow, or save it as an application for double-clicking.
Getting the Contents of Selected Messages
From Automating Spamcop:
set raw to {}
tell application "Mail"
set msgs to selection
if length of msgs is not 0 then
repeat with msg in msgs
set messageSource to source of msg
set raw to raw & messageSource
set background color of msg to gray
end repeat
end if
end tell
Sending E-mail with AppleScript
From Send Email using Applescript:
set recipientName to "WhiteHat"
set recipientAddress to "[email protected]"
set theSubject to "Type your subject here!"
set theContent to "Type your message content here!"
tell application "Mail"
##Create the message
set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
##Set a recipient
tell theMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}
##Send the Message
send
end tell
end tell
Combine, Create, and Send
Combining the two snippets above gives the following AppleScript:
set recipientName to "The Boss"
set recipientAddress to "[email protected]"
set theSubject to "Type your subject here!"
set theCombinedContent to ""
tell application "Mail"
set msgs to selection
if length of msgs is not 0 then
repeat with msg in msgs
set theCombinedContent to theCombinedContent & (content of msg)
-- set background color of msg to gray
end repeat
set theMessage to make new outgoing message with properties {subject:theSubject, content:theCombinedContent, visible:true}
tell theMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}
-- Uncomment line below to automatically send
-- send
end tell
end if
end tell
tell application "Mail"
set theSubject to "Subject" -- the subject
set theContent to "Content" -- the content
set theAddress to "[email protected]" -- the receiver
set theSignatureName to "signature_name"-- the signature name
set theAttachmentFile to "Macintosh HD:Users:moligaloo:Downloads:attachment.pdf" -- the attachment path
set msg to make new outgoing message with properties {subject: theSubject, content: theContent, visible:true}
tell msg to make new to recipient at end of every to recipient with properties {address:theAddress}
tell msg to make new attachment with properties {file name:theAttachmentFile as alias}
set message signature of msg to signature theSignatureName
send msg
end tell