sending mail error.........Could not connect to SMTP host: localhost, port:

package com.shiva;

import java.io.*;

import java.util.*;

import javax.mail.*;

import javax.mail.event.*;

import javax.mail.internet.*;

public final class MailerBean extends Object implements Serializable {

/* Bean Properties */

private String to = null;

private String from = null;

private String subject = null;

private String message = null;

public static Properties props = null;

public static 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 */

public void setTo(String to) {

this.to = to;

}

public void setFrom(String from) {

this.from = from;

}

public void setSubject(String subject) {

this.subject = subject;

}

public void setMessage(String message) {

this.message = message;

}

/* Sends Email */

public void sendMail() throws Exception {

if(!this.everythingIsSet())

throw new 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) {

throw new Exception(e.getMessage());

}

}

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

private boolean everythingIsSet() {

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

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

return false;

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

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

return false;

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

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

return false;

return true;

}

}

I am using this code to send a mail, but i am getting error as............Could not connect to SMTP host: localhost, port:......why i am getting this error. There is no problem with host name.

can any one give me the solution.....urgent

[2352 byte] By [shiva_advensysa] at [2007-10-3 5:25:08]
# 1
Are you actually running an SMTP service on localhost?
cotton.ma at 2007-7-14 23:32:20 > top of Java-index,Java Essentials,Java Programming...
# 2
The magic 8-ball says 'No.'J
jagulara at 2007-7-14 23:32:20 > top of Java-index,Java Essentials,Java Programming...
# 3
no...smtp server is not at our local host., our webhost maintaining it. we know only the name of SMTP ,none other than this.
shiva_advensysa at 2007-7-14 23:32:20 > top of Java-index,Java Essentials,Java Programming...
# 4
> no...smtp server is not at our local host., Well then perhaps you should stop trying to connect to it then.
cotton.ma at 2007-7-14 23:32:20 > top of Java-index,Java Essentials,Java Programming...
# 5
ok....then what is the alternative solution for this. Is there any other way to do.....
shiva_advensysa at 2007-7-14 23:32:20 > top of Java-index,Java Essentials,Java Programming...
# 6
> ok....then what is the alternative solution for this.> Is there any other way to do.....Connect to an SMTP server that actually exists.
cotton.ma at 2007-7-14 23:32:20 > top of Java-index,Java Essentials,Java Programming...
# 7
i got that....but i know SMTP mail server host name only. i used this name only, but i am not getting the result....i am getting above error which i have sended to u
shiva_advensysa at 2007-7-14 23:32:20 > top of Java-index,Java Essentials,Java Programming...
# 8
Aray, SMTP server naam kya hai?
filestreama at 2007-7-14 23:32:20 > top of Java-index,Java Essentials,Java Programming...
# 9
server name is ........ mail.advensysindia.com
shiva_advensysa at 2007-7-14 23:32:20 > top of Java-index,Java Essentials,Java Programming...
# 10
how do i come to know about smtp host on my machine?
milind_javaa at 2007-7-14 23:32:20 > top of Java-index,Java Essentials,Java Programming...
# 11

hey my scenerio is "am using mailserver (not localhost) as a mail server and sending it mail ........and setting the properties for

props.put("mail.smtp.host","x.x.x.x"); this ip is not of local host but still its giving me exception "could not connect to local host"

nested exception is "connection refused" can u tell me what could be the possible reasons .....i have checked the mail server thats working perfectly

Message was edited by:

rajivchaudhary_it

rajivchaudhary_ita at 2007-7-14 23:32:20 > top of Java-index,Java Essentials,Java Programming...