File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java mail - smtp config problem

 
Torque
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Sunesh Kumar
Ranch Hand
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Sivaraman Lakshmanan
Ranch Hand
Posts: 231
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Try pinging the mail server.
 
Darren Edwards
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Anoop Keni
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic