send message in jsp form

hi,
I have jsp page that contain a form, What i want is :
when user click the submit button: an email notification will be send to (any email)
I work offline just to test the sending email, where i can find the sent email? is it in the c:\intpub\mailroot\Queue
this is my code, it didn't work,
i used netbeans with tomcat server , what is this lines means?
// SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
        String host = "smtp.yourisp.net";
what i should write insted of (yourisp) in case of working locally?
Note: the SMTP is installed in my computer

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
 
// Send a simple, single part, text/plain e-mail
public class TestEmail {
 
    public static void main(String[] args) {
 
        // SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
        String to = "vipan@vipan.com";
        String from = "vipan@vipan.com";
        // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
        String host = "smtp.yourisp.net";
 
        // Create properties, get Session
        Properties props = new Properties();
 
        // If using static Transport.send(),
        // need to specify which host to send it to
        props.put("mail.smtp.host", host);
        // To see what is going on behind the scene
        props.put("mail.debug", "true");
        Session session = Session.getInstance(props);
 
        try {
            // Instantiatee a message
            Message msg = new MimeMessage(session);
 
            //Set message attributes
            msg.setFrom(new InternetAddress(from));
            InternetAddress[] address = {new InternetAddress(to)};
            msg.setRecipients(Message.RecipientType.TO, address);
            msg.setSubject("Test E-Mail through Java");
            msg.setSentDate(new Date());
 
            // Set message content
            msg.setText("This is a test of sending a " +
                        "plain text e-mail through Java.\n" +
                        "Here is line 2.");
 
            //Send the message
            Transport.send(msg);
        }
        catch (MessagingException mex) {
            // Prints all nested (chained) exceptions as well
            mex.printStackTrace();
        }
    }
}//End of class

Open in new window

master_programmerAsked:
Who is Participating?
 
KuldeepchaturvediConnect With a Mentor Commented:
if you are not finding the message, and system is not throwing any error.

then
1. You are not looking at the right places for the message
2. System is throwing a error which the code is not catching...
can you paste your debug log of code? it might give us some clues.
0
 
objectsCommented:
it want s the hostname of your smtp server
use localhost or 127.0.0.1 if your smtp server is running on the same machine
0
 
master_programmerAuthor Commented:
hi, it did not work
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
KuldeepchaturvediCommented:
what is the error messages that you are seeing, I see your code has the debug as true..
It shdould be telling exactly what is wrong with the mail if it is not successfully connecting to your smtp server.
0
 
master_programmerAuthor Commented:
there is no error message, but i didn't recive any message? actually i did not know where exactly
the sent messages  will be ,if i am work locally ?
0
 
KuldeepchaturvediCommented:
the message shd be in Inetpub/mailroot/mailbox ... or queue folder where you wd find it.

(in windows env).
0
 
master_programmerAuthor Commented:
the messages did not send yet !!!! I use netbeans with tomcat apache server is this the problem ?
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
 
// Send a simple, single part, text/plain e-mail
public class TestEmail {
 
    public static void main(String[] args) {
 
        // SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
        String to = "vipan@vipan.com";
        String from = "vipan@vipan.com";
        // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
        String host = "smtp.localhost.net";
 
        // Create properties, get Session
        Properties props = new Properties();
 
        // If using static Transport.send(),
        // need to specify which host to send it to
        props.put("mail.smtp.host", host);
        // To see what is going on behind the scene
        props.put("mail.debug", "true");
        Session session = Session.getInstance(props);
 
        try {
            // Instantiatee a message
            Message msg = new MimeMessage(session);
 
            //Set message attributes
            msg.setFrom(new InternetAddress(from));
            InternetAddress[] address = {new InternetAddress(to)};
            msg.setRecipients(Message.RecipientType.TO, address);
            msg.setSubject("Test E-Mail through Java");
            msg.setSentDate(new Date());
 
            // Set message content
            msg.setText("This is a test of sending a " +
                        "plain text e-mail through Java.\n" +
                        "Here is line 2.");
 
            //Send the message
            Transport.send(msg);
        }
        catch (MessagingException mex) {
            // Prints all nested (chained) exceptions as well
            mex.printStackTrace();
        }
    }
}//End of class

Open in new window

0
 
master_programmerAuthor Commented:
sorry but i don't know where is the debug log of code?
0
 
KuldeepchaturvediCommented:
It shd be either on your console. Or in stdout/stderr.logs file..

I thought in one of the post you said that there is no error message.. if you have not looked at the logs, how you can be certain that there are no error messages..
0
 
master_programmerAuthor Commented:
because when i run the page every thing is going ok ,but no message have been sent
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.