[REQ:HELP] Save new Mail msg to local mailbox or move from Drafts

I’m currently running this in Apple Mail:

set theDraftMessage to make new outgoing message with properties {subject:theNewSubject, content:theNewBody}
tell theDraftMessage
	set visible to false
	make new to recipient at end of to recipients with properties {name:theProcessName, address:theDraftRecipient}
end tell
save theDraftMessage

This properly creates a new email message and puts it in the Drafts mailbox that is associated with the recipient mail account.

However, since this process doesn’t create mail messages meant for sending, I would like to save the message into a discrete mailbox, a local mailbox…

So I would need something like:

set theDraftMessage to make new outgoing message with properties {subject:theNewSubject, content:theNewBody}
tell theDraftMessage
	set visible to false
	make new to recipient at end of to recipients with properties {name:theProcessName, address:theDraftRecipient}
end tell
save theDraftMessage to mailbox theDefaultMailbox

But this doesn’t work.

Alternatively, I tried using AppleScript to move the saved message from Drafts to the local mailbox with

set mailbox of theDraftMessage to mailbox theDefaultMailbox

and

move theDraftMessage to mailbox theDefaultMailbox

but both don’t work, even though it is no problem to manually move a message from Drafts to a local mailbox in the GUI.

But for some reason AppleScript neither lets me save a draft directly to a non-Drafts mailbox, nor move a message from Drafts to a non-Drafts mailbox.

Is there anyone who knows a solution or workaround?

tia

Can’t subscribe (bad link), so I have to post a reply. (Sorry.)

Hi, you can’t save outgoing message to the certain mailbox. But you can move from your drafts mailbox after the sending it. But you should specify the account of your local mailbox. Because it isn’ t shared mailbox, it has owner.:


move theDraftMessage of drafts mailbox to mailbox theDefaultMailbox of account "myAccountName"

NOTE: in the snippet above I assume you use shared drafts mailbox (which has owner the Mail.app). If you use drafts mailbox of some certain account (owner - the account, not Mail.app) then you should specify the account for it too:


tell application "Mail"
	tell account "myAccountName" -- here I specify the owner of two mailboxes
		move theDraftMessage of mailbox "myOwnedDraftMailbox" to mailbox "mytheDefaultMailbox"
	end tell
end tell

For example, one of my accounts is named “Gmail”. The name of not shared drafts mailbox on my Mail.app is “[Gmail]/Πρόχειρα” (“drafts” in greek language). The name of my other not shared mailbox is “[Gmail]/Σημαντικά” (“important” in greek language). So, when I want move the message from one mailbox to other, I wrote:


tell application "Mail"
	tell account "Gmail" -- specify account, because they are not shared mailboxes
		move (get message 1 of mailbox "[Gmail]/Πρόχειρα") to mailbox "[Gmail]/Σημαντικά"
	end tell
end tell