Adding Mail accounts when none previously exist

I’m having good success adding accounts to AppleMail with the following script. The only problem I have is when I attempt to add an account to Mail when it’s the first time AppleMail has been run, and no accounts have been previously set up. When this happens, AppleMail displays a popup saying no accounts are in Mail and it prompts the user to fill in a bunch of fields to set one up. Unfortunately when this occurs it seems to ignore the script below and forces the user to do everything manually (which is what I’m trying to avoid). Is there a way around this problem?

To reproduce this problem, just go into AppleMail and delete all the accounts, and then run this script:


set theUsername to "pctest9" 
set thePassword to "abc123b" 
set theFullName to "TestFirst TestLast" 
set theEmailAddresses to "pctest9@myisp.net" 
set theServerName to "outgoing.myisp.net" 
set theAccountName to "MyISP Account" 
set theHostname to "incoming.myisp.net" 
set theSMTPLogin to theUsername 
set theSMTPPassword to thePassword 
tell application "Mail" 
try 
set theNewAccount to make new pop account with properties {name:theAccountName, user name:theUsername, server name:theHostname, password:thePassword, full name:theFullName, email addresses:{theEmailAddresses}} 
on error 
display dialog "Account already in AppleMail." 
end try 
try 
set theSMTPServer to make new smtp server with properties {server name:theServerName} 
set smtp server of theNewAccount to theSMTPServer 
on error 
display dialog "Error creating SMTP server in AppleMail." 
end try 
tell theSMTPServer 
try 
set authentication to password 
set user name to theSMTPLogin 
set password to theSMTPPassword 
on error 
end try 
end tell 
quit 
end tell