User Mario wants to archive 120 accounts in Mail Archiver. For testing I usually have some account information at hand. But the account window in Mail is rather small. 

So I thought about getting the data out with my favourite tool - AppleScript.

As always I'll comment the script. Here is the basic version:

tell application id "com.apple.mail"
   
set theAccounts to get accounts
   
set AccountInfo to {}

   
repeat with theAccount in theAccounts
       
set end of AccountInfo to "New account"
       
set end of AccountInfo to "Name: " & name of theAccount
       
set end of AccountInfo to "Username: " & user name of theAccount
       
set end of AccountInfo to "Servername: " & (server name of theAccount)
       
set end of AccountInfo to "Port: " & (port of theAccount)
   
end repeat
   
return AccountInfo
end tell

The repeat loop goes over all accounts. I can access the name of the account, the user name for IMAP as well as the server name and the port.

The result is okay, but it's not the nice list that I want to end up with:Result of getting accounts with AppleScript

But I already solved the problem of making a file with data in the article on printing a list of selected emails in AppleMail. I'm not trying to build a reusable library here. Therefore, a simple copy-paste-and-adapt works fine here. I ended up with the following script:

set this_data to ""

tell application id "com.apple.mail"
    
--get information from accounts
    
set theAccounts to get accounts
    
set this_data to "Name" & "," & "Username" & "," & "Servername" & "," & "Port" & return
    
    
repeat with theAccount in theAccounts
        
set theName to name of theAccount
        
set Username to user name of theAccount
        
set Servername to (server name of theAccount)
        
set thePort to (port of theAccount)
        
set this_data to this_data & theName & "," & Username & "," & Servername & "," & thePort & return
    
end repeat
    
    
--use file on desktop
    
set this_file to (((path to desktop folderas string) & "apple script data.csv")
    
--write data to file
    
my write_to_file(this_datathis_filetrue)
end tell

--routine for writing data to file
on write_to_file(this_datatarget_fileappend_data)
    
try
        
set the target_file to the target_file as string
        
set the open_target_file to open for access file target_file with write permission
        
if append_data is false then set eof of the open_target_file to 0
        
write this_data to the open_target_file as «class utf8» starting at eof
        
close access the open_target_file
        
return true
        
    
on error
        
try
            
close access file target_file
        
end try
        
return false
    
end try
    
end write_to_file

The script is quite a bit longer than the first version. Like the script for printing the selected emails the data is put into a string variable. The variable is written to the desktop. After double-clicking the file I get a nice list in Numbers:

Now, why has nobody requested automatic adding of IMAP accounts from AppleMail to Mail Archiver?