This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Servlets and the fly likes Need help in running the mail program in servlets....very urgent ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Need help in running the mail program in servlets....very urgent !" Watch "Need help in running the mail program in servlets....very urgent !" New topic
Author

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

ruby mohan
Greenhorn

Joined: Aug 02, 2001
Posts: 4
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.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Need help in running the mail program in servlets....very urgent !
 
jQuery in Action, 3rd edition