Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

send message in jsp form

Posted on 2007-12-01
10
Medium Priority
?
631 Views
Last Modified: 2013-12-17
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

0
Comment
Question by:master_programmer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 92

Expert Comment

by:objects
ID: 20389391
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
 

Author Comment

by:master_programmer
ID: 20390789
hi, it did not work
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 20415326
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:master_programmer
ID: 20418765
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
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 20419826
the message shd be in Inetpub/mailroot/mailbox ... or queue folder where you wd find it.

(in windows env).
0
 

Author Comment

by:master_programmer
ID: 20437680
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
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 1500 total points
ID: 20439051
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
 

Author Comment

by:master_programmer
ID: 20440492
sorry but i don't know where is the debug log of code?
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 20443298
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
 

Author Comment

by:master_programmer
ID: 20445624
because when i run the page every thing is going ok ,but no message have been sent
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question