Sending Mail in JSP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swethak
    New Member
    • May 2008
    • 118

    Sending Mail in JSP

    Hi,


    I want to send an mail using JSP.

    I have a code like that

    Code:
    <%@ page import="sun.net.smtp.SmtpClient, java.io.*" %>
    <%
     String from="eminosoft.sravani@gmail.com";
     String to="eminosoft.sravani@gmail.com";
     try{
         SmtpClient client = new SmtpClient("localhost");
         client.from(from);
         client.to(to);
         PrintStream message = client.startMessage();
         message.println("To: " + to);
         message.println("Subject:  Sending email from JSP!");
         message.println("This was sent from a JSP page!");
         message.println();
         message.println("Cool beans! :-)");
         message.println();     
         message.println();
         client.closeServer();
      }
      catch (IOException e){	
         System.out.println("ERROR SENDING EMAIL:"+e);
      }
    %>
    It runs without any error and also didn't receive the mails .

    plz tell that whats the problem in my code.
    Last edited by Nepomuk; Dec 4 '08, 10:53 AM. Reason: Fixed [CODE] tags
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Do you have a mail server installed on your System?

    Mind you,
    Code:
    SmtpClient client = new SmtpClient("localhost");
    isn't necessary, as "localhost" is the standard value. Just
    Code:
    SmtpClient client = new SmtpClient();
    will do the same job. But of course, that's your choice.

    Also, that library isn't officially supported and might be changed. You may want to use JavaMail instead.

    Greetings,
    Nepomuk
    Last edited by Nepomuk; Dec 4 '08, 10:58 AM. Reason: Added Information

    Comment

    Working...