If my mail server requires authentication to send messages, how do I set my username/password through the JavaMail API so I don't get a 'javax.mail.SendFailedException: 550 Relaying is prohibited' error?

John Zukowski

When you connect to the Transport you can pass a username and password:

Transport transport = 
  host, username, password);

Unfortunately, this doesn't use the Authenticator class in javax.mail, so you would have to build in your own mechanism to prompt the user for this information.

You may also need to set the mail.smtp.auth property to true:

props.put("mail.smtp.auth", "true");