Solved

sending email

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
configure dependency in POM for new database 3 34
iterator/ListIterator approach 17 39
Is there a simpler dropbox system? 10 34
Bot application - advice 3 38
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

861 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