Mail.app refuses to accept new account

Hello,

I use the following code to try to create a new mail account on Ventura.

tell application "Mail"
	set AccountName to "online@mail.net"
	set newacct to make new pop account with properties {name:AccountName, user name:AccountName, server name:"pop3.mailhosted.net"}
	tell newacct
		set password to "myPassword"
		set full name to AccountName
		set email addresses to {AccountName}
		set port to 995
		set uses ssl to true
	end tell
	-- no account is created
	set smtpservername to "smtp.mailhosted.net"
	set smtpusername to AccountName
	set addsmtp to make new smtp server with properties {server name:smtpservername}
	tell addsmtp
		set authentication to "password"
		set password to "myPassword"
		set uses ssl to true
		set port to 465
		set user name to AccountName
	end tell
	-- no smtp server is created
	set newsmtpserver to smtp server (smtpservername) -- & ":" & smtpusername) – last part uncomented gives an compiler error
	set smtp server of newacct to smtp server newsmtpserver
	-- noting added as smtp server to the new account
end tell

(Backtick tags for posting AppleScript code on MacScripter added by NG. See the Markdown Reference here.)

If I do it manually it works fine but not in code, what do I wrong? What code part is wrong? Has this to do with some security settings, or…? Being busy for the whole day till bed time, I can’t figure it out. Any suggestions or solutions?

The result of the script is really weird. Trying with a minimal script:

tell application "Mail"
	
	set AccountName to "online@mail.net"
	set newacct to make new pop account with properties {name:AccountName, user name:AccountName, server name:"pop3.mailhosted.net"}
end tell

The result was " account id “0683AEBF-4367-44F1-B957-5ABCDB560BB9” of application “Mail”". So the script DID create an account.

When I ask for a list of accounts:

tell application "Mail"
	get name of accounts
end tell

Then the result includes the new account:

{“iCloud”, “Beatrix”, “xxx”, “Gmx”, “b@gmail.com”, “b@gmail.com”, “Mothsoftware-Test”, “Outlook Live”, “AOL”, “Exchange”, “Notifications Mothsoftware”, “Yahoo!”, “online@mail.net”}

But neither the Settings in Mail nor the Internet Accounts in System Settings show the account. I even restarted Mail.

Thank you for to watch my issue.

Your right, it makes one like a ghost account but never get into the accounts list; even after the ‘newAcct’ is created ( for so far ), you can’t get any info or data from it. Also when called multiply times you get multiply ghost accounts; but they are disappeared when restart Mail.

Really weird.

This issue is happening at least from Catalina → Ventura ( Sonoma not tested )

I’m on Sonoma latest beta. I could do a ticket with Apple. However, their interest in fixing any bug is about zero these days.

Please do. Maybe someone get a wake up call over there.

Done. Looking at Feedback cases always depresses me.

Thank you for your idea. I did look into this, but notice two things.
User languages depended; How do I know the German or Dutch name of the button.

I did remember I could get info about a screen when I hoover over the elements ( System 7-9? ). Or was there a tool for that?
Is there a way to do that under MacOS?

I did use

            get every UI element
			--click (every button whose description is "Cancel") --  to close the current window but doesn't work
			
			--tell window 2 or what shouls I use to get a window/sheet handle
			(*
		get every button
		get properties of every button
		get every UI element of every button
	        get every static text
		get properties of every static text
		get every UI element of every static text
		
		get every scroll bar
		get properties of every scroll bar
		get every UI element of every scroll bar
*)

Any way how do I get all of the items following after opening a window?
Is there a way to travers and save all the UI-Items to a file.txt?

Thank you
With your script I see nothing about the group or the sheet.
BTW, how do I get the sheet?

I can open the sheet now, but its not by travers or following the path.


tell application "System Settings"
	reveal pane id "com.apple.Internet-Accounts-Settings.extension"
end tell

tell application "System Events" to tell application process "System Settings"
	repeat until window 1 exists
		delay 0.1
	end repeat
	set frontmost to true
	tell scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window 1
		set classOfUIelements to get class of UI elements
		set propertiesOfButtons to properties of buttons
		click (every button whose description is "button")
			repeat until sheet 1 of sheet 1 of window "Internet Accounts" exists
				delay 0.1 
			end repeat -- runs forever
		
		--set frontmost to true
		-- works
               -- click button 1 of group 2 of scroll area 1 of group 1 of sheet 1 of window "Internet Accounts" of application process "System Settings" of application "System Events"
		click last button of group 2 of scroll area 1 of group 1 of sheet 1 of window "Internet Accounts" of application process "System Settings" of application "System Events"
	end tell
end tell

Why does the wait for sheet is running forever?
How can I actually get a handle on the sheet?
Is there no ‘Last’ button in group 2; using a fixed number to get the add account button is dangerous because there can be coming more or less buttons?
Also often times the System Settings window gets gray and the opened dialog disappears and I have to kill the System Settings App.

Any suggestions?

Hi @rvamerongen.

Is this anything like what you’re trying to achieve?

tell application "System Settings"
	activate
	reveal pane id "com.apple.Internet-Accounts-Settings.extension"
	repeat until (current pane is pane id "com.apple.Internet-Accounts-Settings.extension")
		delay 0.1
	end repeat
end tell

tell application "System Events"
	tell application process "System Settings"
		tell window 1
			tell scroll area 1 of group 1 of group 2 of splitter group 1 of group 1
				click (first button whose description is "button")
			end tell
			tell sheet 1
				repeat until (it exists)
					delay 0.1
				end repeat
				click last button of group 1 of scroll area 1 of group 1
			end tell
		end tell
	end tell
end tell

Hi,

the only thing I can can do is guessing whats on there; I do not get any UI Element.

Like I did guess this line
"click last button of group 2 of scroll area 1 of group 1 of sheet 1 of window “Internet Accounts” of application process “System Settings” of application “System Events”
"

why can’t I get a list of items from the sheet 1?

Also when I do a click, the clicked button changes to some extra menu elements, how can I know that?

BTW,

Thats what I wrote, but then how do I get the sheet elements using an ui elements request.
It returns nothing/empty.