Issues with AppleScript scripting Mail I'm having some problems.  Googling them I found this:

https://discussions.apple.com/thread/8022877

I'm having almost identical problems.  

tell application "Mail" to make new account ...


...appears to succeed from the perspective of the script or Script Editor - if I query Mail with:

get every imap account


the new account is returned there - however, it doesn't appear in Mail's Preferences under the Accounts tab, it doesn't appear in Internet Accounts, and if I restart my Mac and query Mail again for every imap account, it is no longer returned.

--

The other issue I'm having (closely related): I'm able to change some of the properties of an account, but having issues with two of them. (for these code snippets, theAccount has been set to a valid imap account in Mail):

1 enabled property

tell theAccount to set enabled to true


or 

get enabled of theAccount


...gives me "Apple event failed" error.  If I substitute any other readable imap account property in place of "enabled" (eg. name, user name, port, uses ssl, etc.) it returns the appropriate value.  But anything I try to do with that property (get it or set it) gives me that error.  Huh...?? Why that one and only that one?

2 authentication property: 

tell theAccount to set authenticaion to password


...gives "Can’t make password of account [...] into type constant".  That value (password) is one of a number of constants in the dictionary for the Authentication enumeration.  I'm confident I have the syntax correct (in principle) because if I substitute password in the above code with any of the other constants in that enumeration (kerberos 5, md5, none, etc.) it works fine.  Only password gives that error.

Script Editor/AppleScript seems to believe I'm referring to the password property of theAccount, and that makes sense, so the question is how do I use that password enumeration constant? How do I tell Mail that I want to set theAccount's authentication property to that password enumeration constant (and not the password property)?

Anyone have any idea what I am, (or Apple is -- bug?), doing wrong here?

Thanks in advance!



UPDATE the next day:

In hindsight, I should have posted this as two separate questions.

@CJK's answer solves the second one. His/her answer also suggests an answer to my first one as well (ie. it's just an Apple bug) though others may still have insight on that.

I'll mark @CJK's answer as correct on this post, but if anyone else has any answers to the first issue, please comment.  I'll post that issue as a separate post/question, you can then answer there and I'll mark that up and as correct on that post.
This is more of an extended comment rather than an answer, but comments can only contain inline code and not fenced code blocks.

I'm unable to offer insight regarding your first issue, as I am not using Apple Mail at present, but is probably a bug as I'm aware other users have reported that set the enabled of every account to false doesn't work, and that seems relevant to your situation.  The second issue is most likely a bug as well, but possibly one that can be worked around, given that the other enumeration constants you listed are still working.

To illustrate a test case, you can try and execute this line of code:

return "axmd" as constant


and you should get back the md5 constant used by Mail.  This doesn't need to be inside a tell app "Mail" block, but it can be and may make more sense to place it inside one in your final script when using the password enumeration code.  The enumeration code for password is "axct", and hopefully when you execute this line of (test) code:

return "axct" as constant


you'll get back the password constant.  Probably the best way to make use of this in your script is to do so something like this:

tell application id "com.apple.mail"
    set axct to "axct" as constant
                .
                .
    # Other bits of your code including where
    # you define "theAccount", which should be
    # variable containing a reference to an
    # object with class 'account'
                .
                .
    set the authentication of theAccount to axct
                .
                .
    # Rest of your Mail-specific code
end tell