Solved

sending email

Posted on 2002-04-08
4
155 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
  • 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

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.

757 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

19 Experts available now in Live!

Get 1:1 Help Now