justin66

Q: Mac Mail AppleScript Help

I am using this script with 10.10 and I am unable to use in with 10.11 and above. In 10.11 it creates the account, but once the mail app closes it disappears and in 10.12 it does nothing that I can see in the mail preferences.

 

Is there another way to add a mail account or even an internet account?

 

Any help would be greatly appreciated.

 

--Non-Working Chunk--

 

tell application "Mail" to quit

set First1 to the text returned of (display dialog "What is your First Name?" default answer "" buttons {"Cancel", "Next"} default button 2)

set Last1 to the text returned of (display dialog "What is your Last Name?" default answer "" buttons {"Cancel", "Next"} default button 2)

set theUsername to the text returned of (display dialog "What is your e-mail address?" default answer "" buttons {"Cancel", "Next"} default button 2)

set thePassword to the text returned of (display dialog "What is your password?" default answer "" buttons {"Cancel", "Next"} default button 2 with hidden answer)

 

 

-- Variables

 

 

set outgoing_server to "smtp.gmail.com"

set outgoing_port to "587"

set incoming_server to "imap.gmail.com"

set incoming_port to "993"

set theFullName to First1 & " " & Last1 & " "

 

 

 

 

-- Build IMAP Gmail Account

 

 

tell application "Mail"

  set AccountName to First1 & " " & Last1 & " "

  set newacct to make new imap account with properties {name:AccountName, user name:theUsername, port:incoming_port, uses ssl:true, authentication:("axct" as constant), server name:incoming_server}

  tell newacct

  set password to thePassword

  set full name to AccountName

  set email addresses to theUsername

 

  end tell

 

  set mysmtp to make new smtp server with properties {server name:outgoing_server, port:outgoing_port, uses ssl:true, authentication:("axct" as constant), user name:theUsername, name:"Google"}

  tell mysmtp

  set password to thePassword

  end tell

  set smtp server of newacct to mysmtp

 

end tell

 

 

 

 

Posted on Sep 14, 2016 7:44 PM

Close

Q: Mac Mail AppleScript Help

  • All replies
  • Helpful answers

  • by Barney-15E,Helpful

    Barney-15E Barney-15E Sep 15, 2016 5:03 AM in response to justin66
    Level 9 (50,141 points)
    Mac OS X
    Sep 15, 2016 5:03 AM in response to justin66

    I don't know the answer, but it seems all new accounts are created through the Internet Accounts System Prefs. You can add one in the Mail App itself, but it seems to use the same framework as Internet Accounts does. It may be that the accounts must be created through that framework and Mail cannot, on its own, create the accounts.

  • by justin66,

    justin66 justin66 Sep 15, 2016 5:04 AM in response to Barney-15E
    Level 1 (4 points)
    Mac OS X
    Sep 15, 2016 5:04 AM in response to Barney-15E

    i think you are right. I am just not sure how to talk to the Internet Accounts framework with Apple Script.

  • by Luis Sequeira1,Helpful

    Luis Sequeira1 Luis Sequeira1 Sep 18, 2016 3:33 PM in response to justin66
    Level 6 (12,196 points)
    Mac OS X
    Sep 18, 2016 3:33 PM in response to justin66

    Maybe this bit can help you.

    I was able to get System Preferences to switch to the Internet Accounts pane by issuing this:

     

    tell application "System Preferences"

     

      activate

      reveal pane "Internet

    Accounts"

    end tell

     

     

    (curiously the name of the pane includes an end-of-line character, not a space, between the two words).

     

    From then on, you might be able to adapt your script so it talks to the application "System Preferences", or maybe the pane itself, instead of "Mail".