Tuesday, September 21, 2021

#1 2009-01-06 08:52:35 pm

daisy
Member
Registered: 2009-01-07
Posts: 2

Script to select ACCOUNT from which mail is sent (Apple Mail)

I am an obvious newbie trying to create a simple script in MAIL (OSX).
I simply want to fill in the "To", "Subject" and "Message" fields and then send the email.
I have been successful except for the following:
Under the subject field is an "Account" field which lists several of my accounts.
How do I  select one of those accounts?

The script I have defaults to the account that is listed when the "new message" is opened. I would like to be able to select a particular one.

Many Thanks in advance.

Offline

 

#2 2009-01-07 03:05:06 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11749
Website

Re: Script to select ACCOUNT from which mail is sent (Apple Mail)

Hi,

the sender account should have the format

"John Doe <john@doe.com>"

here's an example to choose the sender account from a list,
but of course you can set it explicitly

Applescript:


tell application "Mail"
   set listOfSenders to {}
   set everyAccount to every account
   repeat with eachAccount in everyAccount
       set everyEmailAddress to email addresses of eachAccount
       if (everyEmailAddress is not equal to missing value) then
           repeat with eachEmailAddress in everyEmailAddress
               set listOfSenders to listOfSenders & {(full name of eachAccount & " <" & eachEmailAddress & ">") as string}
           end repeat
       end if
   end repeat
end tell

set theResult to choose from list listOfSenders with prompt ¬
   "Which account would you like to send this message from?"
if theResult is not equal to false then
   set theSender to item 1 of theResult
end if

tell application "Mail"
   --…
   try
       set sender to theSender
   end try
   --…
end tell

Last edited by StefanK (2009-01-07 03:06:42 am)


regards

Stefan


Filed under: mail

Offline

 

#3 2009-01-09 12:55:41 pm

daisy
Member
Registered: 2009-01-07
Posts: 2

Re: Script to select ACCOUNT from which mail is sent (Apple Mail)

Sorry for the delay in responding. I was sent to the Gulag for a couple of days for failing to follow protocol.

Thanks for the above script. It doesn't solve my specific problem but definitely helps me wrap my brain around AppleScript a little better and I thank you for that.

In the simple "send a letter script" that I am trying to write I know the account name that I want to use. I am not trying to select a particular account name from a list. I would like the script to use the specific account name that I want.

I am able to tell "mail" to send a new message, complete the subject line, complete the content line, and create the text of the message. But I am unable to tell it to use a specific account from which the message should be sent. If I send a letter manually I am able to choose from a scroll down menu and select the specific account. I need that last task done automatically to select a PREDETERMINED specific account.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)