E-mailing data with Java Servlets

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.  
ane4kaAsked:
Who is Participating?
 
Giant2Connect With a Mentor Commented:
See this for an example about sending e-mail.
http://www.javaalmanac.com/egs/javax.mail/SendApp.html
0
 
Giant2Commented:
Sure.
All the job could be done by a Servlet that receive the data, organize them and send the mail.
0
 
ane4kaAuthor Commented:
Can you pleasegive me some details or code sample how 'send e-mail' part should be programmed.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Giant2Commented:
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
 
Giant2Commented:
>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
 
Giant2Commented:
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
 
ane4kaAuthor Commented:
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
 
gdrnecConnect With a Mentor Commented:
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
 
Giant2Commented:
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
 
ane4kaAuthor Commented:
I accepted your final answer.
Let me know if you want me to accept all of them...
0
 
Giant2Commented:
>I accepted your final answer.

See better, please. You accept the answer of gdrnec, not the mine.
Bye, Giant.
0
 
gdrnecCommented:
Have I been stepping on toes here. If so I do appologize.

I only want to help.

Geoff
0
 
VenabiliCommented:
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
 
ane4kaAuthor Commented:
Venabili,

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

Thanks,
0
 
VenabiliCommented:
Question reopened :)
Sorry for the late reaction - was offline :(

Venabili
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.