• Post Reply Bookmark Topic Watch Topic
  • New Topic

javaMail and loosing my marbles!  RSS feed

 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this SMTP server that I'm trying to get into. Now I had the code working this morning and I haven't changed it! And Now I'm getting this error...

javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect


Why does it say localhost when in the code I'm giving it the mail server's address?

Please help!!

Rachel
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pressuming you have checked carefully that no one has changed the mail.smtp.host entry in the Properties you use to get the Session (and no one has) then this is odd. You can enable SMTP debugging (see the docs) to get a better view of what JavaMail is up to. Other than that you can check that you are not remapping the host URL somewhere else (on Windows in %WINDOWS%\System32\drivers\etc\hosts for example). You might also be using an IP address for your host on a network where IP addresses are dynamic. I don't know if JavaMail defaults to localhost, but it might.
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure that no-one has changed the code - I'm the only one at the code.

I'm going to take your advice and check the SMTP debugging. Is that in the javadocs or online at sun?

Thanks!

Rachel
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so I put in the debug and the debug said that it is trying to connect to "localhost"?

Here is my code

Properties p = new Properties();
p.setProperty("mail.transport.protocol", "smtp");

p.setProperty("mail.smtp.host", "mail.myserver.com");
p.setProperty("mail.smtp.port", "25");

Session session = Session.getDefaultInstance(p, null);
session.setDebug(true);


I'll keep trying.
Cheers,
Rachel
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Success!

Changed it from getDefaultInstance to getInstance. Don't ask me why but it worked!

Cheers,
Rachel
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!