javamail send error



Hi,

I am using javamail 1.4 API to send messages through a SMTP server.
The problem is I get the following error:

550 5.7.1 Unable to relay for a@xxxxx
(I have changed the actual address here-but it's a valid address)

Note: The Outgoing server requires authentication.
Probably I'm going wrong there...
Is there any way to verify if authentication has succeeded or not?

One more thing, there is no problem accessing Inbox - Incoming mail
(IMAP) works absolutely fine ...

Here is the code:



package Mail;

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import javax.swing.*;
import com.sun.mail.smtp.SMTPMessage;

// Send a simple, single part, text/plain e-mail
public class TestEmail {

public static void main(String[] args) {

String to = "a@xxxxx";
String from = "a@xxxxx";
String host = "a.b.c.d";//actual host string is entered here

// Create properties, get Session
Properties props = new Properties();

props.put("mail.smtp.host", host);
// To see what is going on behind the scene
props.put("mail.debug", "true");
Session session = Session.getInstance(props);

try {
// Instantiate a message
SMTPMessage msg = new SMTPMessage(session);

//Set message attributes
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(toBofa)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Test E-Mail through Java");
msg.setSentDate(new Date());



// Set message content
msg.setText("This is a test of sending a " +
"plain text e-mail through Java.\n" +
"Here is line 2.");


// to enable authentication
Transport tr = session.getTransport("smtp");
String username="domain\username";//here actual domain and
username are entered
String password=JOptionPane.showInputDialog("Enter pwd for
"+username);

try {
System.out.println("Trying to connect...");
tr.connect(host, username, password);
System.out.println("Hopefully
connected..."+tr.toString());
}
catch (AuthenticationFailedException ex)
{
JOptionPane.showMessageDialog(null,"Transport connect
failed");
}
JOptionPane.showMessageDialog(null,"Authenticated");
msg.saveChanges();
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();
// end of authentication snippet

}
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
}
}
}

Output:
DEBUG SMTP: trying to connect to host "a.b.c.d", port 25, isSSL false
220 <host string> Microsoft ESMTP MAIL Service, Version: 5.0.2195.6713
ready at Wed, 8 Feb 2006 08:31:49 -0600
DEBUG SMTP: connected to host "a.b.c.d", port: 25
..
..
..
..
MAIL FROM:<a@xxxxx>
250 2.1.0 a@xxxxxxxxxxxxxxx OK
RCPT TO:<a@xxxxx>
550 5.7.1 Unable to relay for a@xxxxx
DEBUG SMTP: Invalid Addresses
DEBUG SMTP: a@xxxxx
DEBUG SMTP: Sending failed because of invalid destination addresses
RSET
250 2.0.0 Resetting

.



Relevant Pages

  • Re: Exchange ignores Smart Host settings
    ... could be my virtual SMTP that refuses to relay for some weird reason. ... > BellSouth may require authentication in order to relay through them. ...
    (microsoft.public.exchange.admin)
  • Re: redundant wan links - need 2 relay host
    ... Actually I was not authenticating using smtp to neither one of them. ... smtp relay because there is authentication. ... because exchange is configured with a relay host of the primary ISP. ...
    (microsoft.public.exchange.admin)
  • sendmail client side smtp authentication problem
    ... sendmail client side smtp authentication problem ... made and installed cf, restarted sendmail, ... # Resolve map (to check if a host exists in check_mail) ...
    (freebsd-questions)
  • Re: Incoming mail for recipients not in my domain
    ... you can always have them use their own ISP's SMTP server to send ... If you turn off authenticated relay, ... > authentication' and 'Integrated Windows authentication' are enabled. ...
    (microsoft.public.exchange2000.admin)
  • Re: allow authenticated relay?
    ... The problem is on our second SMTP virtual server, setup on a different port, ... the authentication screen and internet side FQDN in the delivery areas. ... The default setting in SMTP server settings, Relay Restrictions is: ...
    (microsoft.public.exchange.admin)