JavaMail error in getting message variable

Hi SDN,

try{

PrintWriter out=response.getWriter();

InitialContext ctx=new InitialContext();

Session session = (Session) ctx.lookup("java:comp/env/mail/Email");

Properties props = session.getProperties();

out.println("Mail From >>" + props.getProperty("mail.from")); //senders email id

out.println("SMTP Server >>" + props.getProperty("mail.smtp.host")); // SMPT mail server name

Message message = new MimeMessage(session);

message.setFrom(new InternetAddress(props.getProperty("mail.from")));

message.setRecipients(Message.RecipientType.TO, new InternetAddress[]{new InternetAddress(request.getParameter("Receipient"))});

essage.setSubject(request.getParameter("Subject"));

message.setContent(request.getParameter("Msg"),"text/plain");

out.println("Message variable value" + message.getRecipients(Message.RecipientType.TO));

Transport.send(message);

out.println("

<b>Thank U. Your Message to "+request.getParameter("Recipient")+"was succesfully sent.<b>");

}

catch(Exception e)

{

e.printStackTrace();

}

We could not able to send a mail to the specified address using SMTP . Actual problem is the message variable in the above coding could not set the specified "from" address or "receipient" address . When we tried to display the set value it is returning the address as "Ljavax.mail.internet.InternetAddress;@57cd1b" . So suggest me how to overcome this.

[1522 byte] By [Basha.sa] at [2007-10-2 14:26:03]
«« JVM
»» menu
# 1
getRecipients returns an array.Instead of setContent, you might want to use the setText method,although I don't think that has anything to do with your problem.To figure out why the message isn't being sent, you need to lookat the protocol trace.
bshannona at 2007-7-13 12:45:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Hi bshannonThanks for u'r quick reply. S i used setText also but no use. Then how to trace this protocol.RegardsBasha
Basha.sa at 2007-7-13 12:45:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
http://java.sun.com/products/javamail/FAQ.html#debug
bshannona at 2007-7-13 12:45:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

Hi bshannon

I think the problem is not with the content method . when we try to set from address and To address using the corresponding methods , the value is not set. When we tried to get back internet address (TO, FROM) it is returning some other unknown address.

Regards

Basha

Basha.sa at 2007-7-13 12:45:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
Read the FAQ entry and send me the protocol trace, along with theoutput you get from your program.
bshannona at 2007-7-13 12:45:53 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...