1 Reply Latest reply: Jul 16, 2012 3:07 AM by gimbal2 RSS

    not able to send email using jsp

    934730
      Hi sir,
      I have developed one jsp page for sending main to gmail account, for that purpose i have kept two jar files, mail.jar, jaf.jar in the lib folder. where i m doing mistake, i m not getting,

      the codes are as:

      <%
      try{
      Session mailSession = Session.getInstance(System.getProperties());
      Transport transport = new SMTPTransport(mailSession,new URLName("smtp.gmail.com"));
      transport.connect("smtp.gmail.com",25,null,null);
      MimeMessage m = new MimeMessage(mailSession);
      m.setFrom(new InternetAddress(%><%request.getParameter("from")%><%));
      Address[] toAddr = new InternetAddress[] {
      new InternetAddress(%><%request.getParameter("to")%><%)
      };
      m.setRecipients(javax.mail.Message.RecipientType.TO, toAddr );
      m.setSubject(%><%request.getParameter("subject")%><%);
      m.setSentDate(new java.util.Date());
      m.setContent(%><%request.getParameter("description")%><%, "text/plain");
      transport.sendMessage(m,m.getAllRecipients());
      transport.close();
      out.println("Thanks for sending mail!");
      }
      catch(Exception e){
      out.println(e.getMessage());
      e.printStackTrace();
      }
      %>

      Regards
      Inam