Solved

sending email

Posted on 2002-04-08
4
162 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 100 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

Independent Software Vendors: 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!

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

615 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