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
Solved

E-mailing data with Java Servlets

Posted on 2004-10-05
17
305 Views
Last Modified: 2013-11-24
I have a Java Servlets application that runs on WebLogic Server. Is it possible to create a following functionality with java servlets:

User of the application should click a button; the servlet would be called that would collect and send data (preferably in an excel format) to an assigned e-mail address.  

Please let me know if and how is it possible to do.  
0
Comment
Question by:ane4ka
  • 7
  • 4
  • 2
  • +1
17 Comments
 
LVL 12

Expert Comment

by:Giant2
ID: 12227795
Sure.
All the job could be done by a Servlet that receive the data, organize them and send the mail.
0
 
LVL 12

Accepted Solution

by:
Giant2 earned 125 total points
ID: 12227807
See this for an example about sending e-mail.
http://www.javaalmanac.com/egs/javax.mail/SendApp.html
0
 

Author Comment

by:ane4ka
ID: 12227826
Can you pleasegive me some details or code sample how 'send e-mail' part should be programmed.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 12

Expert Comment

by:Giant2
ID: 12227834
I suggest you to not use Excel format , but CSV format. It's really more lite.
For excel format you can see al jakarta POI:
http://jakarta.apache.org/poi/hssf/

Hope all these things could help you.
Bye, Giant.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12227892
>Can you pleasegive me some details or code sample how 'send e-mail' part should be programmed
In the first link I post there is a clear example.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12227927
client click a button, so a request is sent to a servlet (name it as XYSerlet).

In the doPost method of the XYServlet the things you must do are the following:
read the data needing
create the file (cvs) as suggest
send the mail (you can use the send method present in the link).
0
 

Author Comment

by:ane4ka
ID: 12228235
Thanks a lot for all your suggestions and examples.
One more question.  Do I have to download any packages for the e-mail to work (Ex: javax.mail)

Thanks!
0
 
LVL 4

Assisted Solution

by:gdrnec
gdrnec earned 125 total points
ID: 12229360
javax.mail is in the J2EE packages. If you don't have it you can download it at http://java.sun.com. I think it is also available as a separate package if you don't need the whole j2ee.jar

BTW. I didn't follow the link for the sample code but here is a class that does mail if you need it.

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

/**
 *
 * @author  gdrnec
 */
public class MailHandler {
    private Session session;
    private String from = "bob@loadsaenergy.com";
    /** Creates a new instance of MailHandler */
    public MailHandler() {
        // Get system properties
        Properties props = System.getProperties();
       
        // Setup mail server
        props.put("mail.smtp.host", "smtp.loadsaenergy.com");
       
        try {
            // Get session
            session = Session.getDefaultInstance(props, null);
        } catch (Exception X) {
            System.out.println("Coudn't create mail session. " + X.getMessage());
        }
    }
   
    public void sendMail(String to, String msg, String subject) {
        try {            
            // Define message
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            message.setSubject(subject);
            message.setText(msg);
           
            // Send message
            Transport.send(message);
        } catch (Exception X) {
            System.out.println("Couldn't send mail. " + X.getMessage());
        }        
    }
   
}
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12234704
ane4ka,
you told:
Thanks a lot for all your suggestions and examples.
BUT you don't accept my answer.
If you have a mistake, please send a 0point post to the Support asking to reopen this question. When it's reopen you could reassing the points.

If you don't a mistake, THANKS wery much.

Bye, Giant.
0
 

Author Comment

by:ane4ka
ID: 12239017
I accepted your final answer.
Let me know if you want me to accept all of them...
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12239068
>I accepted your final answer.

See better, please. You accept the answer of gdrnec, not the mine.
Bye, Giant.
0
 
LVL 4

Expert Comment

by:gdrnec
ID: 12239092
Have I been stepping on toes here. If so I do appologize.

I only want to help.

Geoff
0
 
LVL 20

Expert Comment

by:Venabili
ID: 12256503
ane4ka,

Want me to reopen so you can make a split or reassign here? You had given the points not to the person that had worked with you and to whom you think you had given them :)

Venabili
Java Page Editor
0
 

Author Comment

by:ane4ka
ID: 12258685
Venabili,

Yes please reopen the case, so I can reassign; I didn't realize there were to poeple involved.

Thanks,
0
 
LVL 20

Expert Comment

by:Venabili
ID: 12275110
Question reopened :)
Sorry for the late reaction - was offline :(

Venabili
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse with Angularjs2.0 3 57
runtime exception 2 42
Cisco ASA: Java web start no go, asdm launcher no go 3 37
Running JavaFX on the Raspberry Pi 27 40
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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…

860 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