Solved

sending email

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat startup error 5 136
JavaFX TableView not displaying correctly 3 109
Java program running SQL query 5 50
How to fix  socket closed error 11 32
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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:

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