JavaMail basic
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   rajni_abey
Posted On:   Wednesday, October 30, 2002 10:54 AM

Registration for Password Hi, I am new to Javamail. I have the following code to send a email message to a specified email address. But I don't understand how the message can go to the specified email address with the parameters entered by a client. Please help! import java.util.Vector; import java.util.Properties; import java.util.Date; import javax.mail.Session; import javax.mail.Message; import javax.mail.Transport; import javax.mail.URLName; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class MailTest {    More>>
Registration for Password

Hi,


I am new to Javamail. I have the following code to send a email message to a specified email address. But I don't understand how the message can go to the specified email address with the parameters entered by a client.
Please help!






import java.util.Vector;


import java.util.Properties;


import java.util.Date;




import javax.mail.Session;


import javax.mail.Message;


import javax.mail.Transport;


import javax.mail.URLName;


import javax.mail.internet.InternetAddress;


import javax.mail.internet.MimeMessage;




public class MailTest {




public static void main(String[] a) throws Exception


{




String from = "d123@hotmail.com";


String subject = "Subject is testing javamail..";


String body = "Body is hope this code works..";


String to = "D123@yahoo.com";




Properties props = new Properties();


props.put("mail.transport.protocol","smtp");


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


props.put("mail.user",to);


Session session = Session.getDefaultInstance(props, null);


//formation of message


Message msg = new MimeMessage(session);




InternetAddress[] toAddress = null;


InternetAddress[] fromAddress = null;










try{


toAddress = InternetAddress.parse (to);


fromAddress = InternetAddress.parse (from);


if(fromAddress.length >0) {


if(fromAddress[0] != null) {


msg.setFrom(fromAddress[0]);


}


}




msg.setRecipients (Message.RecipientType.TO, toAddress);


msg.setRecipients (Message.RecipientType.CC, fromAddress);


msg.setSubject (subject);


msg.setSentDate (new Date());


msg.setText (body);


msg.saveChanges();


Transport.send (msg);


}catch(Exception e) {


e.printStackTrace();


}


}


}





Now I have another html file where people will enter information to send a email to me using javamail.



























Please enter the the following information to get a username and password





action="http://ipaddress/Experiments/Test.html">

















































Name :
E-mail Address :
Oraganization :
Phone :












My question is what do I connect to the submit button in order for the information to be emailed to any specified email account? Could somebody please help as I am new to this technology.



Thank you for your time. I really appreciate it!

   <<Less
About | Sitemap | Contact