Java mail.

Use this code

String host ="";// give ur mail server name or IP I hope u will be having local mail server

// or configure gmail. Through that I think u can send mail.

//Get system properties

Properties props = System.getProperties();

//Setup mail server

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

props.put("mail.smtp.auth","true");

//props.setProperty("mail.smtp.dsn.notify",

//"SUCCESS,FAILURE ORCPT=rfc822;sachincr@gmail.com");

props.setProperty("mail.smtp.dsn.ret","FULL");

//Get session

Session session = Session.getDefaultInstance(props,new Authenticator(){

protected PasswordAuthentication getPassWordAuthentication(){

returnnew PasswordAuthentication("userName","passwd");// give ur username and passwd}

});

session.setDebug(true);

String[] mailingList ={"hjj@gmail.com","hjk.jk@rediffmail.com"};

//Define message

MimeMessage message =new MimeMessage(session);

try{

message.setFrom(new InternetAddress("sachincr@gmail.com"));

for (int i = 0; i < mailingList.length; i++){

message.addRecipient(

Message.RecipientType.TO,

new InternetAddress(mailingList[i]));

}

message.setSubject("This is my firts mail");

//message.setText("Welcome to JavaMail");

BodyPart messageBodyPart =new MimeBodyPart();

//Fill the message

//messageBodyPart.setText("Pardon Ideas");

String data ="HTML content of the file "// read the HTML file and store that into data variable

messageBodyPart.setContent(data,"text/html");

Multipart multipart =new MimeMultipart();

multipart.addBodyPart(messageBodyPart);

message.setContent(multipart);

//Send message

message.saveChanges();// implicit with send()

Transport transport = session.getTransport("smtp");

transport.connect(host,"username","passwd");// give ur username and passwd

transport.sendMessage(message, message.getAllRecipients());

transport.close();

}catch (MessagingException messagingException){

messagingException.printStackTrace();

//System.exit(9);//

}

}

[3961 byte] By [arun_manacauda] at [2007-11-26 23:49:21]
# 1
WHAT?
Bairama at 2007-7-11 15:25:52 > top of Java-index,Java Essentials,New To Java...
# 2
is this the solution or?or do you want us to write a question for it? :-)
G_Abubakra at 2007-7-11 15:25:52 > top of Java-index,Java Essentials,New To Java...
# 3
> is this the solution or?> > or do you want us to write a question for it? :-)I think I have figured out the question of this topic.. it is ...How to send mail in java? :D
diptaPBa at 2007-7-11 15:25:52 > top of Java-index,Java Essentials,New To Java...
# 4

> I think I have figured out the question of this

> topic.. it is ...

>

> How to send mail in java? :D

heheheh.. diptaPB i think that is not a question, that is an answer before a question, so he is giving us a solution the he/she will time travel backward in the past and ask the question.. lol.. t

G_Abubakra at 2007-7-11 15:25:52 > top of Java-index,Java Essentials,New To Java...