• Post Reply Bookmark Topic Watch Topic
  • New Topic

Send Mail problem  RSS feed

 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to send an email from my servlet. For that I am using JavaMail API. I do have all the classpath settings.
I am using Apache JServ.
This is the wrapper classpath settings for my JServ.
wrapper.classpath=C:\javamail-1.2\mail.jar;C:\javamail-1.2\mailapi.jar;C:\javamail-1.2\smtp.jar;C:\javamail-1.2\pop3.jar;
wrapper.classpath=C:\jaf-1.0.1\activation.jar;
For more safety I added all the jar files in the classpath.
Now I am sending a mail.
But no mail is being sent.\
The code that I am using is this : ( which is posted here in the Saloon)
public class SendMail2 extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)
{
try
{
res.setContentType("text/html");
String from = "";
String to = "";
String subject = "the subject u wanna send ";
String cc="";
String bcc="";
String text="the matter that u wanna send ";
java.util.Properties prop = System.getProperties();
prop.put("mail.smtp.host","mail.yahoo.com");
getServletContext().log("props"+prop);
Session ses = Session.getInstance(prop,null);
MimeMessage message = new MimeMessage(ses);
getServletContext().log("mimemessage"+message);
try
{
Address fromAddress = new InternetAddress(from);
message.setFrom(fromAddress);
message.setSubject(subject);
Address[] toAddress = InternetAddress.parse(to);
Address[] cc_address=InternetAddress.parse(cc);
Address[] bcc_address=InternetAddress.parse(bcc);
message.setRecipients(Message.RecipientType.TO,toAddress);
message.setRecipients(Message.RecipientType.CC,cc_address);
message.setRecipients(Message.RecipientType.BCC,bcc_address);
message.setSentDate(new java.util.Date());
message.setText(text);
PrintWriter out = res.getWriter();
out.println("message sent");
getServletContext().log("mimemessage"+message.text);
Transport.send(message);
}
catch(Exception e)
{
System.out.println("Problem " + e);
}
}
catch(Exception e)
{
}
}
};

Any idea of how will I correct this problem ?
Thanks,
Maya
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!