sunny51
January 28th, 2005, 06:03 AM
am trying to send a mail from a Servlet( tomcat ) and
getting the following exception:
Could not connect to SMTP host: localhost, port 25
The code for a function is :-
public void sendMessage(String hostname,String to, String from,String subject, String message ) throws MessagingException
{
boolean debug = true;
//Set the host smtp address
Properties props = System.getProperties();
props.put("mail.smtp.host", hostname);
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
System.getProperties().list(System.out);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress addressTo = new InternetAddress(to);
msg.setRecipient(Message.RecipientType.TO, addressTo);
msg.setRecipient(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
Pleas help me, have spent 2 days trying to solve the problem but without any luck.
Thanks
getting the following exception:
Could not connect to SMTP host: localhost, port 25
The code for a function is :-
public void sendMessage(String hostname,String to, String from,String subject, String message ) throws MessagingException
{
boolean debug = true;
//Set the host smtp address
Properties props = System.getProperties();
props.put("mail.smtp.host", hostname);
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
System.getProperties().list(System.out);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress addressTo = new InternetAddress(to);
msg.setRecipient(Message.RecipientType.TO, addressTo);
msg.setRecipient(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
Pleas help me, have spent 2 days trying to solve the problem but without any luck.
Thanks