Link to home
Start Free TrialLog in
Avatar of czh81
czh81

asked on

javamail exception Could not connect to SMTP host: smtp.myhost.com, port: 25, response: -1

I tried to use javamail to send email from java file
I tried to turn off my Norton AntiVirus, but still not work
I can telnet my mail host with port 25 so looks like the port 25 is available
I can go to my mail host's web site login with my user name and password.
What response -1 means?
what else could be wrong?
I can ping my email server(it is working).
My laptop is Windows XP . My labtop connects to Internet throgh RCN internet service.
I did go to this website http://scan.sygate.com/
to check, it said port 25 not open
I went to control panel-security center and it said Firewall not monitored.(so it means the firewall already been disabled)
Start -> Run -> cmd -> telnet myhost.com:25 will shows connection to myhost.com could not open connection to the
host on port 23: connection failed (why it says port 23 I don't understand)

if I try this Start -> Run -> cmd -> telnet myhost.com 25 it will open another window but shows nothing

Can somebody user your smpt host info to run my code to see if it is my code's problem or something else.
Maybe my ISP blocked port 25. If so how can I open it?
javax.mail.MessagingException: Could not connect to SMTP host: smtp.myhost.com, port: 25, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1215)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:322)


my code:**********************************************

public class sendmail3 {
public static void main(String arg[])
{
//Get system properties
Properties props = System.getProperties();
Session session = Session.getDefaultInstance(props, null);
// Setup mail server
java.util.Properties sessionProperties = new java.util.Properties();

sessionProperties.put("mail.smtp.auth", "true");
sessionProperties.put("mail.smtp.port", "25");



// Define message
javax.mail.internet.MimeMessage message = new javax.mail.internet.MimeMessage(session);
try{
message.setFrom(new javax.mail.internet.InternetAddress("mymail@myhost.com"));

message.addRecipient(
javax.mail.Message.RecipientType.TO,
new javax.mail.internet.InternetAddress("czh81@hotmail.com"));

message.setSubject("test");
message.setContent("this is a test", "text/plain");

// Send message - This is the line that causes the smtp debug and the network activity
Transport t = session.getTransport("smtp");
t.connect("smtp.myhost.com", "myusername","mypasswor") ;
// send the message
Transport.send(message);
}
catch(Exception e)
{
e.printStackTrace();
}

}


ASKER CERTIFIED SOLUTION
Avatar of InteractiveMind
InteractiveMind
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of czh81
czh81

ASKER

I did try sessionProperties.put("mail.smtp.auth", "false"); no luck

Avatar of czh81

ASKER

it is working now. The reason I can not send email because my ISP 's issue. I have to put my ISN's smtp address as my host.
Thanks for help.