File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Port of SMTP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Port of SMTP" Watch "Port of SMTP" New topic
Author

Port of SMTP

Naresh Rajan
Ranch Hand

Joined: Sep 08, 2005
Posts: 45
Hi,
I have been trying to send a mail from my application. It tries and fails every time giving an exception

Cannot send email. javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: Could not connect to SMTP host: inmumm05.tcs.com, port: 25
javax.mail.SendFailedException: Sending failed;

I have a property file which contains all the data to be sent. Here I have mentioned the port number but it does not seem to have an effect. It always says port 25. Please help.


Am not a pro and thats why am here!!!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Does inmumm05.tcs.com accept connections on port 25? If it does, can you show us the code where you apply your Java Mail properties and the contents of your properties file?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Naresh Rajan
Ranch Hand

Joined: Sep 08, 2005
Posts: 45
No it does not accept. I tried it out. I tried printing the contents of the Property file and it prints the value properly but it does not pass on the value to Transport.

I actually took the code from the net. It is available at

http://www.javapractices.com/Topic144.cjp

It needs the mail.jar and activation.jar in the classpath

Regards.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
The best way to find whether a port is action in a particular host is by telneting.

Telnet host port

if connection not refused then thats a listening port in the host.


Rahul Bhattacharjee
LinkedIn - Blog
Naresh Rajan
Ranch Hand

Joined: Sep 08, 2005
Posts: 45
Thanks Rahul. I found out that the port number. But still my application seems to have a problem. Is there any problem regarding my protocol???
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
From the exception it seems like its not able to connect to the host.

Have you tried the telnet stuff?

One more thing to check would be whether the name to IP resolution is taking place properly.If not you can use the IP directly in place of host to see what happens.
Naresh Rajan
Ranch Hand

Joined: Sep 08, 2005
Posts: 45
Rahul,
I tried the telnet stuff and it is connecting. but my application is not working. I cannot get the IP address. The name is correct though!!
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by Naresh Rajan:
Rahul,
I tried the telnet stuff and it is connecting. but my application is not working. I cannot get the IP address. The name is correct though!!


try the following to get the IP address

ping <your_machine_name>

The response will have something like
Pinging with x bytes <your_machine_name> [your_IP]
Now use your_IP
Manish Narang
Greenhorn

Joined: Apr 29, 2011
Posts: 3
Rahul Bhattacharjee wrote:
Originally posted by Naresh Rajan:
Rahul,
I tried the telnet stuff and it is connecting. but my application is not working. I cannot get the IP address. The name is correct though!!


try the following to get the IP address

ping <your_machine_name>

The response will have something like
Pinging with x bytes <your_machine_name> [your_IP]
Now use your_IP


Hi even i am facing the same problem, even if i replace HostName with the IP of the server , i am getting the same error.

javax.mail.MessagingException: Could not connect to SMTP host: 10.35.55.203, port: 25, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1270)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at com.jnj.email.p.MailSender.sendMail(MailSender.java:59)
at com.jnj.email.p.MailSender.main(MailSender.java:23)
Could you please help?

I can ping the server, i can telnet the server with port 25, everything is fine. but SAME ERROR.

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4658
    
    5

Manish Narang wrote:
javax.mail.MessagingException: Could not connect to SMTP host: 10.35.55.203, port: 25, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1270)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at com.jnj.email.p.MailSender.sendMail(MailSender.java:59)
at com.jnj.email.p.MailSender.main(MailSender.java:23)
Could you please help?



The error message is actually quite informative. That server is not answering on port 25.
You need to contact that host's admin and see if they support SMTP input, and if so, do they require TLS, SSH, etc.

Its not a programming error, its an admin/usage issue
Manish Narang
Greenhorn

Joined: Apr 29, 2011
Posts: 3
Pat Farrell wrote:
Manish Narang wrote:
javax.mail.MessagingException: Could not connect to SMTP host: 10.35.55.203, port: 25, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1270)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at com.jnj.email.p.MailSender.sendMail(MailSender.java:59)
at com.jnj.email.p.MailSender.main(MailSender.java:23)
Could you please help?



The error message is actually quite informative. That server is not answering on port 25.
You need to contact that host's admin and see if they support SMTP input, and if so, do they require TLS, SSH, etc.

Its not a programming error, its an admin/usage issue


Thanks for your reply Farrell..!
Pat Farrell: The scenario is like, we use the same smtp host in our all three env's (DEV, TEST, PROD). This program runs FINE in Production servers but not in others..
so can it be a problem with the smtp host server or DEV and TEST servers ?
i mean should contact the team which supports smtp host or DEV/TEST servers ?
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4658
    
    5

Manish Narang wrote:The scenario is like, we use the same smtp host in our all three env's (DEV, TEST, PROD). This program runs FINE in Production servers but not in others..
so can it be a problem with the smtp host server or DEV and TEST servers ?
i mean should contact the team which supports smtp host or DEV/TEST servers ?


Yes, perhaps they are not running Postfix or sendmail on the dev/test servers.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Manish Narang wrote:Thanks for your reply Farrell..!
Pat Farrell: The scenario is like, we use the same smtp host in our all three env's (DEV, TEST, PROD). This program runs FINE in Production servers but not in others..
so can it be a problem with the smtp host server or DEV and TEST servers ?
i mean should contact the team which supports smtp host or DEV/TEST servers ?


Sounds to me like the people who manage the SMTP server have configured it to only accept requests from specific machines. If this were my problem I wouldn't be asking random strangers to speculate about the problem, though, I would be asking the SMTP server managers.
Manish Narang
Greenhorn

Joined: Apr 29, 2011
Posts: 3
Hi All,
My problem is solved. Just wanted to inform that the problem was: "SMTP Relay was not enabled for our TEST and DEV servers on the SMTP HOST". requested them to enable it and it works great...!!!

Thanks all for your help!!!

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Port of SMTP