Solved

send message in jsp form

Posted on 2007-12-01
10
624 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
  • 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
 

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This short article will present "How to import ICS Calendar onto Office 365 Calendar". I was searching for free (or not free) tools to convert ICS to CSV without success. The only tools I found & working well were online tools...this was too hard to…
Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now