Results 1 to 4 of 4

Thread: How to send e-mail through JSP

  1. #1
    Erick Ballmer is offline Member
    Join Date
    Jun 2009
    Posts
    53
    Rep Power
    3

    Default How to send e-mail through JSP

    Hi everyone. I am last year MCA student. I am learning JSP programming language. I want code for send e-mail through JSP. I tried different code but none of them worked out. Please give me some proper code. Thanks in advanced.

  2. #2
    Join Date
    Jun 2009
    Posts
    41
    Rep Power
    0

    Default

    Refer following program to send e-mail through JSP:
    Code:
    SendMail.html
    <HTML> 
    <BODY> 
    <FORM METHOD=POST ACTION="DemoSendMail.jsp"> 
    Receiver name: <INPUT TYPE=TEXT NAME=username SIZE=20><BR> 
    Receiver email address: <INPUT TYPE=TEXT NAME=email SIZE=20><BR> 
    <P><INPUT TYPE=SUBMIT> 
    </FORM> 
    </BODY> 
    </HTML>
    DemoSendMail.jsp
    <%@ taglib prefix="blx" uri="/blx.tld" %> 
    <HTML> 
    <BODY> 
    <% 
      // Get username. 
      String email = request.getParameter( "email" ); 
    %> 
    <% if ( email == null || email.equals( "" )) { %> 
    Please enter an email address again. 
    <% } else { %> 
    <blx:email host="yoursmtphost.com" from=" test@yahoo.com">  
    <blx:emailTo><%= email %></blx:emailTo>  
    Thank you for registering with us.  You registered the 
    following name: <%= request.getParameter( "username" ) %> 
    You are registered<%= new java.util.Date() %> 
    
    <!--  Also write out some HTML --> 
    Thank you.  A confirmation email has been sent to <%= email %> 
    <% } %> 
    </BODY> 
    </HTML>

  3. #3
    Erick Ballmer is offline Member
    Join Date
    Jun 2009
    Posts
    53
    Rep Power
    3

    Default

    I have tried the given code but it didn’t solve my problem. Please try to provide some other solution.

  4. #4
    Join Date
    Jun 2009
    Posts
    44
    Rep Power
    0

    Default

    Try this:


    Code:
    <html>
    <head>
    <title>JSP JavaMail Example </title>
    </head>
    <body>
    <%@ page import="java.util.*" %>
    <%@ page import="javax.mail.*" %>
    <%@ page import="javax.mail.internet.*" %>
    <%@ page import="javax.activation.*" %>
    <%
    String host = "yourmailhost";
    String to = request.getParameter("to");
    String from = request.getParameter("from");
    String subject = request.getParameter("subject");
    String messageText = request.getParameter("body");
    boolean sessionDebug = false;
    // Create some properties and get the default Session.
    Properties props = System.getProperties();
    props.put("mail.host", host);
    props.put("mail.transport.protocol", "smtp");
    Session mailSession = Session.getDefaultInstance(props, null);
    mailSession.setDebug(sessionDebug);
    Message msg = new MimeMessage(mailSession);
    msg.setFrom(new InternetAddress(from));
    InternetAddress[] address = {new InternetAddress(to)};
    msg.setRecipients(Message.RecipientType.TO, address);
    msg.setSubject(subject);
    msg.setSentDate(new Date());
    msg.setText(messageText);
    Transport.send(msg);
    out.println("Mail was sent to " + to);
    out.println(" from " + from);
    out.println(" using host " + host + ".");
    %>
    </table>
    </body>
    </html>

Similar Threads

  1. Send mail in ASP.net
    By MartinWilson in forum General Internet Terms
    Replies: 2
    Last Post: 06-22-2010, 01:45 PM
  2. Send mail from a Python script
    By ScottWright in forum Programming
    Replies: 0
    Last Post: 05-12-2010, 01:44 PM
  3. Send mail using VB.net
    By RogersNguyen in forum General Internet Terms
    Replies: 1
    Last Post: 05-07-2010, 01:52 PM
  4. Send mail in PHP
    By Davisricky in forum Programming
    Replies: 2
    Last Post: 04-26-2010, 01:29 PM
  5. Send mail using Gmail SMTP
    By Davisricky in forum Software Jargons
    Replies: 2
    Last Post: 02-13-2010, 02:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48