send mail with attachments

I downloaded a code from-

http://www.stardeveloper.com/articles/display.html?article=2001101101&page=1

it has four files: three files are ok. but there is one bean file.

--

MailerBean.class

--

package com.stardeveloper.bean.test;

import java.io.*;

import java.util.*;

import javax.mail.*;

import javax.mail.event.*;

import javax.mail.internet.*;

publicfinalclass MailerBeanextends Objectimplements Serializable{

/* Bean Properties */

private String to =null;

private String from =null;

private String subject =null;

private String message =null;

publicstatic Properties props =null;

publicstatic Session session =null;

static{

/*Setting Properties for STMP host */

props = System.getProperties();

props.put("mail.smtp.host","mail.yourisp.com");

session = Session.getDefaultInstance(props,null);

}

/* Setter Methods */

publicvoid setTo(String to){

this.to = to;

}

publicvoid setFrom(String from){

this.from = from;

}

publicvoid setSubject(String subject){

this.subject = subject;

}

publicvoid setMessage(String message){

this.message = message;

}

/* Sends Email */

publicvoid sendMail()throws Exception{

if(!this.everythingIsSet())

thrownew Exception("Could not send email.");

try{

MimeMessage message =new MimeMessage(session);

message.setRecipient(Message.RecipientType.TO,

new InternetAddress(this.to));

message.setFrom(new InternetAddress(this.from));

message.setSubject(this.subject);

message.setText(this.message);

Transport.send(message);

}catch (MessagingException e){

thrownew Exception(e.getMessage());

}

}

/* Checks whether all properties have been set or not */

privateboolean everythingIsSet(){

if((this.to ==null) || (this.from ==null) ||

(this.subject ==null) || (this.message ==null))

returnfalse;

if((this.to.indexOf("@") == -1) ||

(this.to.indexOf(".") == -1))

returnfalse;

if((this.from.indexOf("@") == -1) ||

(this.from.indexOf(".") == -1))

returnfalse;

returntrue;

}

}

1. Do i have to give some protocol names.

2. If so how do i find them.

3. I want to send mail from our intranet.(company).

4. I am using NetBeans 5.0. it is asked to save the bean file in a folder in web-inf\classes. but i dont have classses in that folder. Also i dont have libraries folder. Do I have to change any settings?

5. How can i create class for this bean file. If i save it in web-inf, it says u can not save it there and saves it in source packages. What shall i do.

[5857 byte] By [minerva_7a] at [2007-11-26 19:07:49]
# 1

(You found all the free sample source code that's included with JavaMail, right?)

You probably don't need to specify any protocol names, the defaults should work.

You will have to set the properties appropriately for your environment, however.

You'll want to handle this class just like any other Java source file in your

web application. Usually such files are compiled and the resulting class

file ends up in WEB-INF/classes.

bshannona at 2007-7-9 21:00:38 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
But i dont have that classes folder itself. i have created one my seld. But i am not getting any class file.yes i have saved the mail.jar and activation .jar files in my project libraries. other files also i hav stored as told.MailerBean.class not created. why?
minerva_7a at 2007-7-9 21:00:38 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
I have no idea. Are you handling it the same way as all theother Java source files in your application? If those otherfiles aren't getting compiled into the WEB-INF/classes directory,where are they getting compiled into?
bshannona at 2007-7-9 21:00:38 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
thanks for the reply. But i have used mime and the code is working perfectly.I found it. it was saved in biuld/web-inf/classes.Message was edited by: minerva_7
minerva_7a at 2007-7-9 21:00:38 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
Can you help me send a simple email using java... http://forum.java.sun.com/thread.jspa?threadID=5146702&tstart=0Please...
Apya at 2007-7-9 21:00:38 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...