Java SMTP problem: connects but will not send message
In my java application, I successfully connect to my Exchange smtp server using the transport.connect() method (confirmed using a ConnectionListener). However, I get a MessagingException when the transport.sendMessage() method is called. I am using an Authenticator inner class and supplying a "from" email address.
The error message is:
"javax.mail.MessagingException: 454 5.7.3 Client does not have permission to submit mail to this server"
However, if I send an email message using Outlook Express to the same hostname, username and password then the email message is delivered successfully.
Does anyone have any furhter ideas please?
Code snippet:
Properties props =new Properties();
props.put("mail.smtp.host", hostName );
props.put("mail.smtp.port", Integer.toString( port ) );
props.put("mail.smtp.auth","true" );
Session session = Session.getInstance( props,new SMTPAuthenticator() );
Message msg =new MimeMessage( session );
msg.setSubject( messageTitle );
msg.setFrom(new InternetAddress( fromEmail,true ) );
msg.setReplyTo(new InternetAddress[]{new InternetAddress( fromEmail,true )} );
// Create the message part
BodyPart messageBodyPart =new MimeBodyPart();
// Fill the message
messageBodyPart.setText( outgoingMessage.getMessageText() );
Multipart multipart =new MimeMultipart();
multipart.addBodyPart( messageBodyPart );
// Code omitted here to add multipart file attachments......
// Now put all the parts in the message
msg.setContent( multipart );
// Send the message
Transport transport = session.getTransport("smtp" );
transport.connect( );
transport.sendMessage( msg, recipients );
transport.close();
An for the inner class
privateclass SMTPAuthenticatorextends Authenticator{
/**
* Overrides the method in the Authenticator superclass.
* @return The PasswordAuthentication object.
*/
protected PasswordAuthentication getPasswordAuthentication(){
returnnew PasswordAuthentication( userName, password );
}
}

