jQuery in Action, 3rd edition
The moose likes Other JSE/JEE APIs and the fly likes Prob with connecting SMTP on port 25 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Prob with connecting SMTP on port 25" Watch "Prob with connecting SMTP on port 25" New topic

Prob with connecting SMTP on port 25

Tuhin Ghosh
Ranch Hand

Joined: Oct 11, 2006
Posts: 33
hello ranchers,

I am developing a client application which can send and recieve mails from ISP. The recieving part works fine .I m able to connect to the POP server and able to fetch the mail. But i could not able to send the mail. It gives teh forllowing exception:! Any thoughts about wat went wrong


<Oct 31, 2006 12:01:28 PM GMT+05:30> <Warning> <HTTP> <BEA-101248> <[null]: Depl
oyment descriptor "web.xml" is malformed. Check against the DTD: org.xml.sax.SAX
ParseException: cvc-elt.1: Cannot find the declaration of element 'web-app'. (line 2, column 10).>
DEBUG: not loading system providers in <java.home>/lib
DEBUG: not loading optional custom providers file: /META-INF/javamail.providers
DEBUG: successfully loaded default providers

DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPTransport=javax.ma
il.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc
], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.
IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provide
r[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imap=javax.mail.Provider[STORE,imap,com.su
n.mail.imap.IMAPStore,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop
3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], smtp=javax.mail.Provider[T
RANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: not loading optional address map file: /META-INF/javamail.address.map

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.s
mtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true

DEBUG: SMTPTransport trying to connect to host "smtp.ktk.airtelbroadband.in", port 25

javax.mail.MessagingException: Could not connect to SMTP host: smtp.ktk.airtelbr
oadband.in, port: 25;
nested exception is:
java.net.SocketException: Software caused connection abort: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:867)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:15
at javax.mail.Service.connect(Service.java:234)
at javax.mail.Service.connect(Service.java:135)
at mail.sendMessage(mail.java:79)
at mail.doPost(mail.java:36)
at mail.doGet(mail.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)

The Code as follows--------------->>>>>>

import javax.mail.*;
import javax.mail.internet.*;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;

import javax.servlet.*;
import javax.servlet.http.*;

import javax.mail.Transport;

public class mail extends HttpServlet{

private final static String DEFAULT_SERVER="smtp.ktk.airtelbroadband.in";

public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException

String smtpServ="smtp.ktk.airtelbroadband.in";
String from= "";
String to= "";
String subject="subject1";
String emailContent="This is a Test Email";

java.io.PrintWriter out = response.getWriter();

out.println("<html><head><title>Email MEssage sender</title></head></html>");

sendMessage(smtpServ, to, from, subject, emailContent,out);}

catch(Exception e)
throw new ServletException(e.getMessage());
out.println("<h2>The Message was sent successfully</h2>");

private void sendMessage(String smtpServ,String to,String from,String subject,String emailContent,PrintWriter out) throws Exception

Properties properties=System.getProperties();

properties.put("mail.smtp.auth", "true");
properties.put("mail.debug", "true");

Session session=Session.getDefaultInstance(properties);

Message mailMsg=new MimeMessage(session);

Multipart mp = new MimeMultipart();

BodyPart b1 = new MimeBodyPart();




Transport bus = session.getTransport("smtp");
out.println("Message sent");
catch(MessagingException ex)


public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException



Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42958
This may not have anything to do with the problem, but how are you setting username and password?

Can you connect to the host directly by typing "telnet smtp.ktk.airtelbroadband.in 25" on the command line?
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Software caused connection abort: connect

I'd check there are no firewalls or port blocking software between you and your server.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Tuhin Ghosh
Ranch Hand

Joined: Oct 11, 2006
Posts: 33
thanks Ulf and paul,

i did check the telnet smtp.ktk.airtelbroadband.in . Its aborting connection.
Is this an Issue? Coz am successfuly fetching the mail from the same server using POP.

so any other thing that i missed...? which is important.Please tell me.

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Yes it is. If you can't connect via SMTP, you can't use JavaMail (as it is) to send emails.

This sounds like a configuration thing. I wouldn't be suprised if your server admin has stopped anything connecting to his server to send mails, but is happy to allow a connection to retreive them. Speak to him/her/them.
Tuhin Ghosh
Ranch Hand

Joined: Oct 11, 2006
Posts: 33
k one more thing i successfully connected using Outlook. on port 25 with same SMTP name. Guide me !!!


Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14998

<Oct 31, 2006 12:01:28 PM GMT+05:30> <Warning> <HTTP> <BEA-101248> <[null]: Depl
oyment descriptor "web.xml" is malformed. Check against the DTD: org.xml.sax.SAX
ParseException: cvc-elt.1: Cannot find the declaration of element 'web-app'. (line 2, column 10).>

There seems to be something seriously wrong with the deployment descriptor of your web application. The error message suggests you don't have a 'web-app' element in there. Check your deployment descriptor and make sure it is correct.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Tuhin Ghosh:
k one more thing i successfully connected using Outlook. on port 25 with same SMTP name. Guide me !!!



Did you? Out the box Outlook uses MAPI to connect to Exchange - so if you configured a new Microsoft Exchange Server in your Outlook services you are probably connecting via MAPI, not SMTP.

Or it is possible that you have port blocking software stopping applications other than recognized MUAs connecting to the server. Check that.

Still this still sounds like the sort of configuration issue that can be solved easily by speaking to the person in charge of the SMTP server you are trying to connect to.
I agree. Here's the link: http://aspose.com/file-tools
subject: Prob with connecting SMTP on port 25
It's not a secret anymore!