Address bill = new InternetAddress("email@example.com",true); Address elliotte = new InternetAddress("firstname.lastname@example.org",true); System.out.println(elliotte); Message msg = new MimeMessage(mailConnection);
msg.setFrom(bill); msg.setRecipient(Message.RecipientType.BCC, elliotte); msg.setSubject("You must comply."); msg.setContent("Resistance is futile. You will be assimilated!", "text/plain");
A few points (sorry to be critical): Why are you explicitly using strict validation of email addresses when new InternetAddress(java.lang.String address) does this by default? And empty catch blocks will always give you headaches.
Aside from that, both:
are perfectly valid RFC822 email addresses, so neither of these lines should be giving you an AddressException (are you sure that's what you are getting?)
"Access Denied" exceptions will be something to do with the connection to the SMTP server. Does "mail.cloud9.net" need any authentication/authorization? Are you behind a proxy or firewall?
Here's a list of things I always tell people to do when they have problems with JavaMail:
Enable SMTP debugging, so you can see the actual SMTP traffic.
Speak to the SMTP server admin and try to telnet to the server. Both are very quick ways to test whether you actually can access it in the way you want to. Any glitches/restrictions can be ironed out here before you have written a line of Java.
Write Transport and Connection Handlers which log activity properly (good to help you debug problems, and essential if you want the application to be supported by someone else)
Read the JavaMail FAQ's (if you haven't already - this will alert you to common issues people encounter. People are forever misunderstanding the implications of having a proxy server involved in the process for instance.
Develop and test you JavaMail code seperate from your SMTP server. Use Dumbster (or James if you must) to check your code is doing what you want it to, and generating the proper SMTP messages. That way you are not mixing debuging code with debugging infrastructure which makes the process easier in the long run.