javax.mail.MessagingException: Could not connect to SMTP host:

here is a part of my code

import javax.mail.*;

import javax.mail.internet.*;

import java.util.*;

public class Mail {

/** Creates a new instance of PostMail */

public Mail() {

}

public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException

{

boolean debug = false;

//Set the host smtp address

Properties props = new Properties();

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

// create some properties and get the default Session

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

session.setDebug(debug);

// 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[recipients.length];

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

{

addressTo = new InternetAddress(recipients);

}

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

// Optional : You can also set your custom headers in the Email if you Want

msg.addHeader("MyHeaderName", "myHeaderValue");

// Setting the Subject and Content Type

msg.setSubject(subject);

msg.setContent(message, "text/plain");

Transport.send(msg);

}

}

-

Here is the exception i rec'vd

javax.mail.MessagingException: Could not connect to SMTP host: smtp.google.com, port: 25;

nested exception is:

java.net.ConnectException: Connection refused: connect

at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282)

at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)

at javax.mail.Service.connect(Service.java:275)

at javax.mail.Service.connect(Service.java:156)

at javax.mail.Service.connect(Service.java:105)

at javax.mail.Transport.send0(Transport.java:168)

at javax.mail.Transport.send(Transport.java:98)

at Mail.postMail(Mail.java:45)

at ArchMain.<init>(ArchMain.java:30)

at ArchMain$6.run(ArchMain.java:360)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)

at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)

at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

Caused by: java.net.ConnectException: Connection refused: connect

at java.net.PlainSocketImpl.socketConnect(Native Method)

at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)

at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)

at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)

at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)

at java.net.Socket.connect(Socket.java:519)

at java.net.Socket.connect(Socket.java:469)

at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)

at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)

at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1250)

... 17 more

[3644 byte] By [ryshi1264a] at [2007-11-27 5:38:40]
# 1
So there's something in your network that is preventing your code from connecting. That's nothing to do with your code and nothing even to do with Java. It's just a network thing. Could be a firewall or a proxy server or virus protection in action. Talk to your network support people.
DrClapa at 2007-7-12 15:12:32 > top of Java-index,Java Essentials,Java Programming...
# 2

In one of my project i got the same error: The cause was that a virus shield was running on my machine. After disabling it the error was gone. Please check whether there is any virus shield or firewall running on your machine or the gateway you using. If you have some then try to disable it and then run your program.

Hope this helps :)

diptaPBa at 2007-7-12 15:12:32 > top of Java-index,Java Essentials,Java Programming...