• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javaMail and loosing my marbles!

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Success!

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

Cheers,
Rachel
 
reply
    Bookmark Topic Watch Topic
  • New Topic