Do I need to install a SMTP server before using javamail.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Hironmoy_Tamuly
Posted On:   Monday, May 14, 2007 03:35 PM

Do I need to install a SMTP server before using javamail? I have done the following program and i m using jboss as my server. try{ //set up the default parameters. Properties props = new Properties(); props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.host", "localhost"); props.put("mail.smtp.port", "25"); //create the session and create the new mail message Session mailSession = Session.getInstance(props); Message msg = new MimeMessage(mailSession); //set the FROM, TO, DATE and SUBJECT fields msg.setFrom(new InternetAddress   More>>

Do I need to install a SMTP server before using javamail?
I have done the following program and i m using jboss as my server.


try{

//set up the default parameters.

Properties props = new Properties();

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

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

props.put("mail.smtp.port", "25");


//create the session and create the new mail message

Session mailSession = Session.getInstance(props);

Message msg = new MimeMessage(mailSession);


//set the FROM, TO, DATE and SUBJECT fields

msg.setFrom(new InternetAddress("me@hiron.com"));

msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("htamuly@yahoo.com"));

msg.setSentDate(new Date());

msg.setSubject("Testing my send mail method");


//create the body of the mail

msg.setText("Hello! from my first java e-mail...Testing!!");


//ask the Transport class to send our mail message

Transport.send(msg);

System.out.println("E-mail successfully sent!!");


}catch(Exception e){

e.printStackTrace();

}



I am getting the following exception----


javax.mail.MessagingException: Unknown SMTP host: localhost, and i have given the port number 25.

   <<Less

Re: Do I need to install a SMTP server before using javamail.

Posted By:   Robert_Lybarger  
Posted On:   Monday, May 14, 2007 08:33 PM

Well, yeah ... "javamail" API is just a fancy wrapper around opening a TCP socket connection on port 25 of some server and sending SMTP command statements to it. That's all. Twenty lines of code and you can get rid of javamail for all simple messages. (In fact, I usually do just that.) So, yes ... you actually need to provide a real SMTP-based mail transfer agent somewhere that you point the javamail configuration at. (Examples include sendmail in the UNIX world and MS Exchange in the Windows world.)
About | Sitemap | Contact