Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sending email

Posted on 2002-04-08
4
Medium Priority
?
164 Views
Last Modified: 2013-11-24
All i want to do is send an email via html and then display a sent email page using java... This is what i currently have...

<form action="mailto:cardiboys.com.au" method="post" ENCTYPE= text/plain >

<p><textarea name="Question 5.     " cols="55" rows="4"></textarea></p>

<INPUT TYPE="submit" name="submit">

</form>    

what sort of java code do i need to add, to submit the form and then display the next page... Next page is called thanks.html
0
Comment
Question by:Yakeni
[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
  • 2
4 Comments
 
LVL 2

Expert Comment

by:coreyit
ID: 6927122
If you want to use mailto as the form action, your users will always be sending the email from a spawned instance of their email client. It is possible for you to use javascript to have the form submit action also cause the browser location to change to your thank you page, but that would be a little odd since the user won't necessarily have sent the email by the time the thank you page loads.

You'd be much better off having your form submit to a servlet which processes the input and send you an email, after which it would forward or redirect to your thank you page.

-corey
0
 
LVL 1

Expert Comment

by:jose_tijo
ID: 6927356
Hi
   From the code you have give the browser will open the mail client installed in the users machine. Please let me know whether you are asking for java code to send email.

if so you can use the following code:
 
 public static String sendMail() {
          Properties properties = new Properties();
          properties.put("mail.smtp.host", "<your smtp host>");
          properties.put("mail.from", "Sun Microystems");
         
          Session session = Session.getInstance(properties,null);
         
          try {
               Message message = new MimeMessage(session);
               int i=0;
               InternetAddress[] address = {new InternetAddress("<address here>")};
               message.setRecipients(Message.RecipientType.TO, address);
               message.setFrom(new InternetAddress("fromaddress@here.com"));
               message.setSubject("Hi");
               message.setContent(mail_Content, "text/html");
               transport = session.getTransport(address[0]);
                                        transport.connect();
                    transport.sendMessage(message,address);
                              }catch (Exception e) {
               System.out.println("Exception: " + e.toString());
               return "Error sending Mail";
           }
          return "Mail Successfully Send!";
     }
0
 
LVL 1

Accepted Solution

by:
jose_tijo earned 400 total points
ID: 6927357
Hi
   From the code you have give the browser will open the mail client installed in the users machine. Please let me know whether you are asking for java code to send email.

if so you can use the following code:
 
 public static String sendMail() {
          Properties properties = new Properties();
          properties.put("mail.smtp.host", "<your smtp host>");
          properties.put("mail.from", "Sun Microystems");
         
          Session session = Session.getInstance(properties,null);
         
          try {
               Message message = new MimeMessage(session);
               int i=0;
               InternetAddress[] address = {new InternetAddress("<address here>")};
               message.setRecipients(Message.RecipientType.TO, address);
               message.setFrom(new InternetAddress("fromaddress@here.com"));
               message.setSubject("Hi");
               message.setContent(mail_Content, "text/html");
               transport = session.getTransport(address[0]);
                                        transport.connect();
                    transport.sendMessage(message,address);
                              }catch (Exception e) {
               System.out.println("Exception: " + e.toString());
               return "Error sending Mail";
           }
          return "Mail Successfully Send!";
     }
0
 

Author Comment

by:Yakeni
ID: 6935913
Cheers Buddy
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

730 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