Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Need AppleScript to Forward Email to Specific Person

I need an AppleScript to forward the selected message to a specific e-mail address. I want to be able to insert a comment in the message area at the top of the message thread—just as if I were doing it manually.


I have a script that creates a new message and copies the contents of the selected message to it. However, I lose all the formatting.


Can someone help me? Thanks.

MacBook Air, Mac OS X (10.7.2)

Posted on Jun 16, 2012 7:16 AM

Reply
6 replies

Jun 16, 2012 7:39 AM in response to Michael Hyatt1

By the way, this works, but it is pretty cludgy. I'd prefer controlling the app directly if possible:


tell application "System Events"

tell process "Mail"

set frontmost to true

click menu item "Forward" of menu 1 of menu bar item "Message" of menu bar 1

keystroke "myassistant@mydomain.com"


keystroketab


keystroketab


keystroketab


keystroketab


keystroketab


keystroketab


keystroketab


keystroketab

keystroke "Please schedule a meeting."


delay 1


clickmenu item "Send" of menu 1 of menu bar item "Message" of menu bar 1

end tell

end tell

Jun 16, 2012 8:25 AM in response to Michael Hyatt1

Maybe a compromise:


set myComment to "My comment: "

set theName to "Some name"

set theAddress to "Some email address"


try

set the clipboard tomyComment

tell application "Mail"

set theSelection to selection

set theForwardedMessage to forward (item 1 of theSelection) with opening window

tell theForwardedMessage

makenewto recipientat end of to recipientswith properties {name:theName, address:theAddress}

end tell

activate

tell application "System Events" to keystroke "v" using {command down}

delay 1

sendtheForwardedMessage

end tell

end try

Aug 22, 2013 2:14 AM in response to Pierre L.

Hi Pierre,


Thanks for your solution, and I have additional question to above AppleScript:


since I have different E-mail Accounts(inclusive of POP & IMAP account)


I mean the mail I want forward is received from POP Account(Say "aAccount"), and I want to forward it by IMAP account (Say "bAccount")


How can I improve the AppleScript?


Pleased to hear.


Kind Regards,

Donnel

Feb 27, 2014 11:16 PM in response to Pierre L.

I'm using this paste technique to do a mail forwarding like OP but I'm using the second last paragraph of the email set to a variable as the comment text.


Watching it loop thru the messages I can see the text gets pasted for a moment and then deleted. The script delays for 1 second then does the next email. I'm not sending them just composing them in Mail.


What could be cuasing the comment text to disappear. Sometimes it stays mostly it gets deleted.


tell application "Mail"

try

set notes to {""}

set email_selection to (get selection)

repeat with a_msg in email_selection

set theText to content of a_msg

set their_name to words 2 thru -1 of paragraph 9 of theText

set comments to paragraph -5 of theText

set subscriber to paragraph 5 of theText

if comments ≠ "comments: " then

set comments_LF to (comments as rich text) & return


set the clipboard tocomments as rich text

copy {subscriber, comments as rich text} to the end of notes

set the_forwarded_message to forwarda_msg with opening window

tell the_forwarded_message

make new to recipient at end of to recipients with properties {name:"Alastair Leith", address:"alastair@publicland.com.au"}

set subject to (their_name as rich text) & " has a comment on subscription form"


activate

tell application "System Events" to keystroke "v" using {command down}

delay 0.1

end tell


end if

tell application "AppleScript Editor"


-- display dialog (notes as text)

end tell

end repeat


-- display dialog (notes as rich text)

return notes


-- display dialog notes

on error the error_messagenumber the error_number

tell application "AppleScript Editor"

display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1

end tell

end try


end tell

Need AppleScript to Forward Email to Specific Person

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.