For reasons more complicated than interesting, I want to use Send Again to reply to incoming e-mails that meet certain specific conditions. I’ve figured out how to extract the sender’s e-mail address from the message, but I can’t figure out how to select a previously sent message and resend it to the new recipient. I’d really appreciate any help. Thanks.
How exactly did you extract the senders email address? --just because I’m looking for this too
I don’t know if this helps but
tell application "Mail"
tell message viewer 1 to set theMessage to item 1 of (get selected messages)
set email@address.com to sender of theMessage
end tell
but this only does it with the first email and it has to be selected I guess… -haven’t tested it yet because I have to search for good ways how to extract an email address from a mail first
I’m using this right now to extract the sender’s address, but I’m not sure if I’m going to need to tweak it when the AppleScript is run as a rule.
tell application "Mail"
set theMessage to selection
set the thisMessage to item 1 of the theMessage
set theSender to sender of the thisMessage
set theAddress to extract address from theSender
end tell
Also, I’ve got the message ID”which I believe is unique”of the e-mail I want to resend. Now, if I could only figure out how to sent again the e-mail with that message ID to the incoming sender.
Maybe this :
tell application "Mail"
set theMessage to selection
set the thisMessage to item 1 of the theMessage
set email@address.com to sender of thisMessage
send thisMessage
end tell
or if you want to send back to the sender :
tell application "Mail"
set theMessage to selection
set the thisMessage to item 1 of the theMessage
send thisMessage
end tell
-Again, haven’t tested them yet…
But my problem is that I need to have Mail its window open, I’d wanna do it without that, I now I can open the window with system events and then close it but before I’ll look into that, I’m going to search for more options…
Thanks for the help. It seems like there are many ways to extract the sender’s e-mail to address the reply. I still have no clue how to select a specific message in the Sent folder and tell Mail to Send Again to the newly acquired address.
If you have the message id it’s quite easy to get the specific message
tell application "Mail"
set messageToSend to 1st message of sent mailbox whose id is 12345
end tell
And how do you change the send inbox in something else ?
tried mailbox “INBOX” but it gave an error
What’s the name of the inbox mailbox ? -or is it a name I gave it to it ? i.e. I have one big icon named “Inbox” and within that I have 3 smaller icons with names like Gmail, Hotmail etc.
But it works with a mailbox with the folder icon into it…
Here’s my current script:
tell application "Mail"
set theMessage to selection
set the thisMessage to item 1 of the theMessage
set theSender to sender of the thisMessage
set theAddress to extract address from theSender
set messageToSend to 1st message of sent mailbox whose id is 343445
set sender of (message messageToSend) to theAddress
end tell
I get this error message on the last line: “Mail got an error: Can’t set message (message id 343445 of mailbox “[Gmail]/Sent Mail” of account “User Name”) to “emailaddress@gmail.com”.”
I’m less concerned about selecting the correct message from the correct inbox, because I plan to run the script on any incoming message that meets specific requirements. (I’m sure my confidence will come back to bite me in the ass.)
mailbox inbox is just inbox, without quotes and without mailbox prefix
this is the message id, not the id
.
set messageToSend to 1st message of sent mailbox whose message id is messageID
.
Thanks both of you!
inbox worked
Me too but the correct box was a question on how to change the send box…
Okay, I’ve got the correct Message ID, and here is the script so far:
tell application "Mail"
set theMessage to selection
set the thisMessage to item 1 of the theMessage
set theSender to sender of the thisMessage
set theAddress to extract address from theSender
set sendAgain to 1st message of sent mailbox whose id is 343445
-- Need to tell Mail to Send Again the message sendAgain
set sender of (message sendAgain) to theAddress
-- Need to send message
end tell
I get the error on the last line: "Mail got an error: Can’t set message (message id 343445 of mailbox “[Gmail]/Sent Mail” of account “User Name”) to “emailaddress@gmail.com”.
Thanks for everyone’s help.
you can’t change any properties of received or sent messages.
A workaround is to create a new outgoing message, copy the relevant parameters and send the message
tell application "Mail"
set theMessage to selection
set the thisMessage to item 1 of the theMessage
set theSender to sender of the thisMessage
set theAddress to extract address from theSender
set messageToSend to 1st message of sent mailbox whose id is 343445
tell messageToSend to set {theSubject, theContent} to {subject, content}
set newMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
tell newMessage
make new to recipient at end of to recipients with properties {name:theSender, address:theAddress}
end tell
send newMessage
end tell
The script is not copying the content of the previously sent message which consists solely of a custom Mail stationary template. That’s part of the reason I thought it would be easier to invoke the command Message > Send Again.
I really can’t tell you how much I appreciate your help.
Evoking “Send again” can be scripted with
tell application "Mail"
activate
set sel to selection
set isSelected to sel is not {}
end tell
if isSelected then
tell application "System Events"
tell process "Mail" to keystroke "d" using {command down, shift down}
end tell
end if
I know this is a case of beggars being choosers, but I was really hoping that the script could operate entirely in the background so it wouldn’t interrupt the workflow of whomever is using my computer.
Instead of using Send Again, is there any way to have Mail automatically choose a certain stationary file?
I don’t think so, there are no appropriate script commands in Mail’s dictionary
Thanks for your help and patience.
If I look at the long header info for the message, there’s a section that says, “X-Apple-Mail-Stationery: D292B188-CE8E-4D60-9E5A-5E0C979579B9”. Any way to possibly use that?
I can also see the raw source for the image-embedded e-mail. I’ve tried copying and pasting various parts into a new message, but all I get on the other end is an e-mail with the raw source”it doesn’t render the code. Is there a way that might work?