Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Java
  4. j2ee code for sending mail [modified]

j2ee code for sending mail [modified]

Scheduled Pinned Locked Moved Java
javacomhelpquestion
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sangeeta2009
    wrote on last edited by
    #1

    J2EE code for sending MAIL ...? I have made 2 files and used one source library 1) a send.jsp ----> file (like a form) http://www.kookle.110mb.com/web\_documents/send.txt 2)make a sendmail.servlet---> file http://www.kookle.110mb.com/web_documents/sendmail.txt 3) used a javamail-1[1].4.2 .rar file as source library But i am not able to send the mail. Please help in getting what i am missing.. please help please reply.........:confused::confused::confused::confused:

    modified on Wednesday, September 9, 2009 7:49 AM

    N 4 2 Replies Last reply
    0
    • S sangeeta2009

      J2EE code for sending MAIL ...? I have made 2 files and used one source library 1) a send.jsp ----> file (like a form) http://www.kookle.110mb.com/web\_documents/send.txt 2)make a sendmail.servlet---> file http://www.kookle.110mb.com/web_documents/sendmail.txt 3) used a javamail-1[1].4.2 .rar file as source library But i am not able to send the mail. Please help in getting what i am missing.. please help please reply.........:confused::confused::confused::confused:

      modified on Wednesday, September 9, 2009 7:49 AM

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      0. Remove you're e-mail address - it's a big invite to the Vikings. 1. Have you tried some diagnostics? Put some logging into your code and find out where things are going Lady Gaga, then post a nice little snippet to show what's gone wrong with an explanation of what you tried. 2. ?? 3. Profit.


      Panic, Chaos, Destruction. My work here is done.

      1 Reply Last reply
      0
      • S sangeeta2009

        J2EE code for sending MAIL ...? I have made 2 files and used one source library 1) a send.jsp ----> file (like a form) http://www.kookle.110mb.com/web\_documents/send.txt 2)make a sendmail.servlet---> file http://www.kookle.110mb.com/web_documents/sendmail.txt 3) used a javamail-1[1].4.2 .rar file as source library But i am not able to send the mail. Please help in getting what i am missing.. please help please reply.........:confused::confused::confused::confused:

        modified on Wednesday, September 9, 2009 7:49 AM

        4 Offline
        4 Offline
        4277480
        wrote on last edited by
        #3

        Sending an Email in Java (Servlet) Prerequisites: 1. Java Mail API (mail.jar) 2. activation.jar 3. HTML Form (Optional) 4. Servlet or JSP (to send the email) Steps: 1. Download and install JDK6U16 2. Download Apache Tomcat 3. Download Eclipse 4. In Eclipse, make sure to add the apache server first 5. Create a dynamic web project 6. Under the WEB-INF create a folder called lib and paste mail.jar and activation.jar 7. Create a jsp and call it index.jsp 8. Create a servlet and call it sendMail 9. Create a class called MyPasswordAuthenticator (will act as authentication or you can use the code inside the sendMail as you like) 10. Create two jsps (success and error) 11. Create a css file called style index.jsp Code:

        <html>
        <head>
        <title>Sending email</title>
        <link rel="stylesheet" href="style.css" type="text/css">
        </head>
        <body>
        <center>
        <form action="sendMail" method="get">
        <table>
        <tr>
        <td>From</td>
        <td><input type="text" name="from"></td>
        </tr>
        <tr>
        <tr>
        <td>To</td>
        <td><input type="text" name="to"></td>
        </tr>
        <tr>
        <td>Subject</td>
        <td><input type="text" name="subject"></td>
        </tr>
        <tr>
        <td>Message</td>
        <td><textarea cols="25" rows="8" name="message"></textarea></td>
        </tr>
        </table>
        <br>
        <input type="submit" value="submit">
        </form>
        </center>
        </body>
        </html>

        style.css

        * { font-size: 12px; font-family: Verdana }
        input, textarea { border: 1px solid #ccc }
        textarea { text-align:left}
        table { margin-top: 10% }
        .error { margin-top: 10%; border: 1px dotted #db1f1f; width: 250px }
        .msg { margin-top: 10%; border: 1px dotted #ccc; width: 250px }

        sendMail Servlet

        import java.util.Properties;
        import javax.mail.Message;
        import javax.mail.Session;
        import javax.mail.Transport;
        import javax.mail.internet.InternetAddress;
        import javax.mail.internet.MimeMessage;
        import javax.servlet.RequestDispatcher;
        import javax.servlet.http.HttpServlet;
        import javax.servlet.http.HttpServletRequest;
        import javax.servlet.http.HttpServletResponse;

        public class sendMail extends HttpServlet
        {
        public void doGet(HttpServletRequest req, HttpServletResponse resp)
        {
        String username = "your gmail account";
        String password = "your gmail password";

        S 1 Reply Last reply
        0
        • 4 4277480

          Sending an Email in Java (Servlet) Prerequisites: 1. Java Mail API (mail.jar) 2. activation.jar 3. HTML Form (Optional) 4. Servlet or JSP (to send the email) Steps: 1. Download and install JDK6U16 2. Download Apache Tomcat 3. Download Eclipse 4. In Eclipse, make sure to add the apache server first 5. Create a dynamic web project 6. Under the WEB-INF create a folder called lib and paste mail.jar and activation.jar 7. Create a jsp and call it index.jsp 8. Create a servlet and call it sendMail 9. Create a class called MyPasswordAuthenticator (will act as authentication or you can use the code inside the sendMail as you like) 10. Create two jsps (success and error) 11. Create a css file called style index.jsp Code:

          <html>
          <head>
          <title>Sending email</title>
          <link rel="stylesheet" href="style.css" type="text/css">
          </head>
          <body>
          <center>
          <form action="sendMail" method="get">
          <table>
          <tr>
          <td>From</td>
          <td><input type="text" name="from"></td>
          </tr>
          <tr>
          <tr>
          <td>To</td>
          <td><input type="text" name="to"></td>
          </tr>
          <tr>
          <td>Subject</td>
          <td><input type="text" name="subject"></td>
          </tr>
          <tr>
          <td>Message</td>
          <td><textarea cols="25" rows="8" name="message"></textarea></td>
          </tr>
          </table>
          <br>
          <input type="submit" value="submit">
          </form>
          </center>
          </body>
          </html>

          style.css

          * { font-size: 12px; font-family: Verdana }
          input, textarea { border: 1px solid #ccc }
          textarea { text-align:left}
          table { margin-top: 10% }
          .error { margin-top: 10%; border: 1px dotted #db1f1f; width: 250px }
          .msg { margin-top: 10%; border: 1px dotted #ccc; width: 250px }

          sendMail Servlet

          import java.util.Properties;
          import javax.mail.Message;
          import javax.mail.Session;
          import javax.mail.Transport;
          import javax.mail.internet.InternetAddress;
          import javax.mail.internet.MimeMessage;
          import javax.servlet.RequestDispatcher;
          import javax.servlet.http.HttpServlet;
          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpServletResponse;

          public class sendMail extends HttpServlet
          {
          public void doGet(HttpServletRequest req, HttpServletResponse resp)
          {
          String username = "your gmail account";
          String password = "your gmail password";

          S Offline
          S Offline
          sangeeta2009
          wrote on last edited by
          #4

          Thanks Member 4277480 for ur reply SIR i deployed your coding in NET-BEANS. The files like index.jsp error.jsp success.jsp style.css MyPasswordAuthenticator.java sendMail.java was easily uploded into it but in case of mail.jar & activation.jar i downloaded the javamail-1.4.2 and jaf-1_1_1 rar files from sun.com and then there is a confusion on by which name they are to be import to source library.. i gave the names javamail-1.4.2 and jaf-1_1_1 and give path to jar files.... i also provided the gmail account and password , but i am not able to send the mail. would you please tell whether you were succeeded in doing it and help me out sir, it is very important for me. please provide a bit more details I need your helping hand please help.... what i think that i haven't configured any smtp server. Could you please tell what should i do for it... i think i am missing this thing only reply soon

          modified on Friday, September 11, 2009 5:17 AM

          4 1 Reply Last reply
          0
          • S sangeeta2009

            Thanks Member 4277480 for ur reply SIR i deployed your coding in NET-BEANS. The files like index.jsp error.jsp success.jsp style.css MyPasswordAuthenticator.java sendMail.java was easily uploded into it but in case of mail.jar & activation.jar i downloaded the javamail-1.4.2 and jaf-1_1_1 rar files from sun.com and then there is a confusion on by which name they are to be import to source library.. i gave the names javamail-1.4.2 and jaf-1_1_1 and give path to jar files.... i also provided the gmail account and password , but i am not able to send the mail. would you please tell whether you were succeeded in doing it and help me out sir, it is very important for me. please provide a bit more details I need your helping hand please help.... what i think that i haven't configured any smtp server. Could you please tell what should i do for it... i think i am missing this thing only reply soon

            modified on Friday, September 11, 2009 5:17 AM

            4 Offline
            4 Offline
            4277480
            wrote on last edited by
            #5

            http://www.mediafire.com/download.php?yygnyhmd1dg 1. Download rar from above. 2. Open it using Eclipse (JDK6U16) 3. When you provide your account make sure its in the format email@gmail.com All done. To setup a personal smtp read this guide: http://www.ehow.com/how\_4489548\_set-up-smtp-server-windows.html Good Luck

            S 1 Reply Last reply
            0
            • 4 4277480

              http://www.mediafire.com/download.php?yygnyhmd1dg 1. Download rar from above. 2. Open it using Eclipse (JDK6U16) 3. When you provide your account make sure its in the format email@gmail.com All done. To setup a personal smtp read this guide: http://www.ehow.com/how\_4489548\_set-up-smtp-server-windows.html Good Luck

              S Offline
              S Offline
              sangeeta2009
              wrote on last edited by
              #6

              hello sir the link you provide http://www.mediafire.com/download.php?yygnyhmd1dg is not working, the rar file is not available.. please look at it also tell me that, the code you provided me is just sufficient to send message or i need to configure a smtp server also.. because i am just running your code please reply soon...

              4 1 Reply Last reply
              0
              • S sangeeta2009

                hello sir the link you provide http://www.mediafire.com/download.php?yygnyhmd1dg is not working, the rar file is not available.. please look at it also tell me that, the code you provided me is just sufficient to send message or i need to configure a smtp server also.. because i am just running your code please reply soon...

                4 Offline
                4 Offline
                4277480
                wrote on last edited by
                #7

                http://rapidshare.com/files/282003437/SendingEmail.rar.html[^] Yes it is sufficient, after extracting the rar open it using Eclipse (with apache) then modify

                String username = "your gmail account"; // in the form myemail@gmail.com
                String password = "your gmail password";

                then launch index.jsp and your done. Good luck

                S 1 Reply Last reply
                0
                • 4 4277480

                  http://rapidshare.com/files/282003437/SendingEmail.rar.html[^] Yes it is sufficient, after extracting the rar open it using Eclipse (with apache) then modify

                  String username = "your gmail account"; // in the form myemail@gmail.com
                  String password = "your gmail password";

                  then launch index.jsp and your done. Good luck

                  S Offline
                  S Offline
                  sangeeta2009
                  wrote on last edited by
                  #8

                  well Member 4277480 i am trying your code but it still not sending them. Tell me whether i have to configure some smtp settings to the gmail account which i am using here. also if possible please send some important screenshot like when configuring tomcat server. also tell me what is this program actually doing, is this sending the mails to any client by using my email address in FROM: option. do i need to configure any port Please help me this last time... I am very close to successfully running it.. Please reply with screenshots

                  4 1 Reply Last reply
                  0
                  • S sangeeta2009

                    well Member 4277480 i am trying your code but it still not sending them. Tell me whether i have to configure some smtp settings to the gmail account which i am using here. also if possible please send some important screenshot like when configuring tomcat server. also tell me what is this program actually doing, is this sending the mails to any client by using my email address in FROM: option. do i need to configure any port Please help me this last time... I am very close to successfully running it.. Please reply with screenshots

                    4 Offline
                    4 Offline
                    4277480
                    wrote on last edited by
                    #9

                    I attached the files again with screenshots: http://rapidshare.com/files/284210076/Email.rar.html[^] But honestly if you have done some web programming this should not take this long to configure. Anyways its always good to help others. Good luck

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups