Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

java mail - smtp config problem

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to send mail from my JSP app. I've followed the instructions for configuring my server.xml to specify the address of my ISP's smtp server, as in:
<Resource name="mail/Session" auth="Container"
type="javax.mail.Session"/>
<ResourceParams name="mail/Session">
<parameter>
<name>mail.smtp.host</name>
<value>smtp.myservername.com</value>
</parameter>
</ResourceParams>
The odd thing is, I get an error message:
javax.servlet.ServletException: Sending failed;
nested exception is:
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
So it looks as though tomcat is looking for the SMTP host on localhost, rather than on the SMTP server I specified.
With a Google search I found a few people asking the same question but no answers, so I guess it's something silly they figured out eventually. Any ideas?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like Tomcat is using localhost as a default because it never picks up that parameter setting.
Bill
 
Torque
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's 18 months later and I had a PM asking how I'd solved the problem. My memory is a bit scratchy, but I think it was that I had a case difference between the server.xml and web.xml, where the web.xml has an entry like this:
<resource-ref>
<res-ref-name>mail/Session</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
</resource-ref>

If I remember rightly, I had Session (capital S) in one place and session (small s) in the other. Just one of those stupid gotchas that eats programming time. Hope this helps someone.
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I too getting the same error. I am using netBeans5.0 can any ine please suggest me the solutions.

javax.servlet.ServletException: Could not connect to SMTP host: localhost, port: 25

Bye
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Try pinging the mail server.
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there meant to be a mailserver running on the localhost, or is the mailserver configuration being ignored? If you're having problems with configuration this JDBC / Javamail Setup may help ...
[ July 10, 2007: Message edited by: Darren Edwards ]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I too had a similar issue of mail not being sent and got the following message

javax.servlet.ServletException: Could not connect to SMTP host: localhost, port: 25

I had to check my application's context.xml in /webroot/META-INF

The problem was "Session" was "session". I changed small "s" to caps "S".

Location 1:
<Resource name="mail/Session" type="javax.mail.Session"/>

Location 2:
<ResourceParams name="mail/Session">
<parameter>
<name>mail.smtp.port</name>
<value>25</value>
</parameter>
<parameter>
<name>mail.smtp.host</name>
<value>smtp.myservername.com</value>
</parameter>
</ResourceParams>

Thanks to Torque for scratching his head.



[ September 08, 2006: Message edited by: Anoop Keni ]
[ September 08, 2006: Message edited by: Anoop Keni ]
 
Always! Wait. Never. Shut up. Look at this tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic