The only problem here is if Mail's folder is locked. If the folder is unlocked, then whether Mail is running or not does not matter (if the "tell application id "com.apple.mail"" launches mail if it's not already running).
To get this to work first make sure that the script is saved as an "Application Bundle":

Then add it to Mail's application associations, and uncheck "Lock on Quit":

Make sure that it's not run upon login by any means. If you need it to run at login, then set the "Launch at Login" option for the association in Espionage.
This means that if the script is launched and Mail isn't running, you'll be prompted to enter the password for Mail's folder, Espionage will unlock the folder, and only after the folder is unlocked will it actually allow the script to be run.
Note: I haven't tested your script to check to see if it will launch the Mail app automatically, if it doesn't do this then you'll need to write some code to first launch Mail, wait until it fully launches, and then tell it to do stuff.