1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Send email through jsp

Discussion in 'JSP' started by dreamer14, Sep 17, 2008.

  1. dreamer14

    dreamer14 New Member

    <%@ page import="java.lang.,java.util.,javax.mail.,javax.mail.internet.,
    javax.activation.*" %>
    String p_to = "abc@hotmail.com"; // Please fill in your email here
    String p_from = "abcd@yahoo.com.sg"; // Please fill in receipient’s email here
    String p_subject = "Testing";
    String p_message = "This is a test email";
    String l_host = "smtp.mail.yahoo.com.sg";
    // Gets the System properties
    Properties l_props = new Properties();
    // Puts the SMTP server name to properties object
    l_props.put("mail.smtp.host", l_host);
    l_props.put("mail.smtp.auth", "true");
    l_props.put("mail.user", "ancde"); 
    // Get the default Session using Properties Object
    Session l_session = Session.getInstance(l_props, null);
    l_session.setDebug(false); // Enable the debug mode
    try {
    MimeMessage l_msg = new MimeMessage(l_session); // Create a New message
    l_msg.setFrom(new InternetAddress(p_from)); // Set the From address
    l_msg.setRecipients( Message.RecipientType.TO
    , InternetAddress.parse(p_to, false));
    l_msg.setSubject(p_subject); // Sets the Subject
    // Create and fill the first message part
    MimeBodyPart l_mbp = new MimeBodyPart();
    // Create the Multipart and its parts to it
    Multipart l_mp = new MimeMultipart();
    // Add the Multipart to the message
    // Set the Date: header
    l_msg.setSentDate(new Date());
    // Send the message
    // If program reaches this point, then message is successfully sent.
    } catch (MessagingException mex) { // Trap the MessagingException Error
    out.print("Failure: Messaging Exception: " + mex);
    } catch (Exception e) {
    out.print("Failure: General Exception: " + e);
    i get this error message
    Failure: Messaging Exception: javax.mail.AuthenticationFailedException
    How do i solve this?
    All help will be greatly appreciated thanks
    Last edited by a moderator: Sep 17, 2008
  2. codestorm

    codestorm New Member

    The error means that the username/password do not match, or the server you are trying access is a paid one.
  3. dreamer14

    dreamer14 New Member

    my username and password is correct so how do i solve that error?

Share This Page