The JavaMail API is designed to use liteners to check connection events. So you can
test whether or not a message made it to the SMTP server easily enough (read the docs to see exaclty how).
I'm not strictly sure what you mean by "mail queue", but its easy enough to persist unsent messages somewhere to be handled by another process. Just write them to a DB table or the file system or whatever, and write some occasional process to read any and try to resend.