• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help in running the mail program in servlets....very urgent !

 
ruby mohan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,
I have downloaded the java mail package and modified the classpath to include the mail.jar and also the activate.jar file.
I was able to compile the program but if i run it in,
I get Page cannot be displayed error is displayed. I use JavaWebserver2.0 and i want to send the email from my local system(not the server) by using the javax mail package.Could anyone help me in this matter how I can send mail.The code which i compiled is:

import javax.mail.*;
import javax.mail.internet.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class SendMail extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
{
try
{
res.setContentType("text/html");
String from="hairuby_tm@yahoo.com";
String to="hairuby_tm@yahoo.com";
String subject="Email Notification";
String cc="ruby_tm@rediffmail.com";
String bcc="ruby_tm@rediffmail.com";
String text="Testing email process";
java.util.Properties prop=System.getProperties();
prop.put("mail.smtp.host","mail.yahoo.com");
Session ses=Session.getInstance(prop,null);
MimeMessage message=new MimeMessage(ses);
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);
Transport.send(message);
}
catch(Exception e)
{
System.out.println("Error"+e);
}
}
catch(Exception e)
{
}
}
}
Can anyone suggest me what to do if i want to send mail using this program.
Thanks in advance,
bye,
ruby.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic