javax.mail.SendFailedException: Sending failed

[nobr]when i execute my code given below it works fine on my machine but when i execute same code on different machine i got exception:->

javax.mail.SendFailedException: Sending failed;

nested exception is:

javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first g25sm6346508wag

message Sending failed;

nested exception is:

javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first g25sm6346508wag

invalid address:-> nullvalid add:-> nullunsent add:-> null[root@192 dep]#

my code is :->

import java.util.*;

import javax.mail.*;

import javax.mail.internet.*;

import javax.activation.*;

publicclass MailClient{

//static String SMTP_SERVER="smtp.bizmail.yahoo.com";

//static String SMTP_USER_NAME="visitindiashop@yahoo.com";

//static String SMTP_USER_PASSWD="4065394";

//static String FROM_USER="visitindia-sales@visitindia.com";

//static String SMTP_PORT="25";

static String SMTP_SERVER="smtp.gmail.com";

static String FROM_USER="xyz@gmail.com";

static String SMTP_USER_NAME="xyz@gmail.com";

static String SMTP_USER_PASSWD="password";

static String SMTP_PORT="587";

publicvoid sendMailTo(Properties props,String from, String to, String subject, String messageText){

try{

//boolean sessionDebug = false;

boolean sessionDebug =true;

String mailer ="VisitIndia";

Authenticator auth =new SMTPAuthenticator();

Session session = Session.getDefaultInstance(props, auth);

//Session session = Session.getInstance(props, auth);

session.setDebug(true);

try{

Message msg =new MimeMessage(session);

msg.setFrom(new InternetAddress(from));

InternetAddress[] addressTo =new InternetAddress[2];

addressTo[0] =new InternetAddress(to);

addressTo[1] =new InternetAddress("xyz@gmail.com");

InternetAddress[] address ={new InternetAddress(to)};

msg.setRecipients(Message.RecipientType.TO, addressTo);

//msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));

msg.setSubject(subject);

msg.setHeader("X-Mailer", mailer);

msg.setSentDate(new Date());

messageText="<html><body><b>ORDER DETAILS:</b> <br> "+

"Thank you for your order from Visitindia Online Shopping. For your convenience, we have sent the copy of your order given below."+

"If you have any billing related query, please feel free to contact at our Customer Care Center between 10:30 am to 7:00 pm IST. For assistance and instructions, visit our web portal at"+

" http://www.visitindia.com</body><img src='http://mail.google.com/mail/help/images/logo1.gif' title='gmail' alt='gmail'></html>";

msg.setContent(messageText,"text/html");

Transport.send(msg);

System.out.println("\nMail was sent successfully.");

}catch (SendFailedException mssEx){

System.out.print("SendFailedException:-> "+mssEx);

System.out.print("message "+mssEx.getLocalizedMessage());

System.out.print("invalid address:-> "+mssEx.getInvalidAddresses());

System.out.print("valid add:-> "+mssEx.getValidSentAddresses());

System.out.print("unsent add:-> "+mssEx.getValidUnsentAddresses());

}

catch (MessagingException mex){

mex.printStackTrace();

}

}catch(Exception e){

// Handle any exceptions, print error message.

//System.err.println(e);

}

}

publicstaticvoid main(String str[]){

// set property for gmail smtp

Properties props = System.getProperties();

props.put("mail.smtp.host",SMTP_SERVER);

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

props.put("mail.smtp.starttls.enable","true");

//props.put("mail.smtp.starttls.enable", true);

props.put("mail.smtp.port", SMTP_PORT);

new MailClient().sendMailTo(props,FROM_USER,"abc@gmail.com","test","hello there, this is a test message");

}

privateclass SMTPAuthenticatorextends javax.mail.Authenticator

{

public PasswordAuthentication getPasswordAuthentication()

{

String username = SMTP_USER_NAME;

String password = SMTP_USER_PASSWD;

returnnew PasswordAuthentication(username, password);

}

}

}

1>I cross check MAIL API and JRE version on both the system they are same.

2>I also added props.put("mail.smtp.starttls.enable", "true"); line in my code.

3>Both machine are windowsXP.

can any one suggest me to debug the problem.[/nobr]

[7579 byte] By [yogeshjoshijia] at [2007-11-27 11:30:24]
# 1

Somehow you've failed to configure the two machines identically.

The JavaMail protocol trace may provide clues.

bshannona at 2007-7-29 16:33:38 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Hi,

Thanks for reply,

Can u guide me what is trace in Java Mail API.

i already enable session debug option.

yogeshjoshijia at 2007-7-29 16:33:38 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Then you should be getting the protocol trace.

bshannona at 2007-7-29 16:33:38 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...