Results 1 to 2 of 2
  1. #1
    nikunj is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default Help with javamail ??

    Hello,
    I am creating a jsp page and trying to send a mail to my gmail account, but my code is not working.

    It giving exception described below:
    javax.servlet.ServletException: javax.mail.AuthenticationFailedException: failed to connect, no password specified?

    index.jsp

    <%--
    Document : index
    Created on : 31 Dec, 2010, 1:43:51 PM
    Author : NIKUNJ
    --%>

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">



    <html>
    <body>
    <form action="sendMail.jsp" method="post">
    <table cellspacing="2" cellpadding="2" border="1">
    <tr>
    <td>To:</td>
    <td>
    <input type="text" name="to" size="30" maxlength="30">
    </td>
    </tr>
    <tr>
    <td>From:</td>
    <td>
    <input type="text" name="from" size="30" maxlength="30">
    </td>
    </tr>
    <tr>
    <td>Subject</td>
    <td>
    <input type="text" name="subject" size="30" maxlength="30">
    </td>
    </tr>
    <tr>
    <td colspan="2">
    <textarea cols="40" rows="10" name="body"></textarea>
    </td>
    </tr>
    <tr>
    <td>
    <input type="submit" name="submit" value="Submit">
    <input type="Reset">
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>


    sendMail.jsp

    <%--
    Document : sendMail
    Created on : 31 Dec, 2010, 1:44:48 PM
    Author : NIKUNJ
    --%>

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <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 = "smtp.gmail.com";

    String to = request.getParameter("to");
    String from = request.getParameter("from");
    String subject = request.getParameter("subject");
    String messageText = request.getParameter("body");
    boolean sessionDebug = true;

    Properties props = System.getProperties();
    props.put("mail.host", host);
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.starttls.enable","true");
    props.put("mail.smtp.auth", "true");

    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 transport = mailSession.getTransport("smtp");
    transport.connect(host, "nikunj2512@gmail.com", "password");
    // here in place of password i am giving my account password.
    transport.send(msg);

    out.println("Mail was sent to " + to);
    out.println(" from " + from);
    out.println(" using host " + host + ".");

    %>

    </body>
    </html>


    Please help, how i can solve this problem..

  2. #2
    baloda is offline Member
    Join Date
    Nov 2010
    Location
    New Delhi
    Posts
    50
    Rep Power
    0

Similar Threads

  1. Javamail
    By johniem in forum New To Java
    Replies: 0
    Last Post: 07-14-2010, 03:00 PM
  2. JavaMail API
    By eponcedeleon in forum Advanced Java
    Replies: 1
    Last Post: 02-28-2010, 12:39 AM
  3. Javamail
    By johniem in forum New To Java
    Replies: 1
    Last Post: 01-29-2010, 03:24 PM
  4. JavaMail Jar
    By rummy in forum Advanced Java
    Replies: 1
    Last Post: 01-21-2010, 03:51 PM
  5. Javamail
    By v_mallikarjun in forum Advanced Java
    Replies: 14
    Last Post: 04-18-2008, 07:32 PM

Posting Permissions

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