JavaMail problem: Could not connect to SMTP host: localhost, port: 25
843834May 29 2008 — edited Jun 2 2008Hi,
I am currently developing a java application to send mails using javamail API. I installed a mail server (hmailserver) to test locally, my mail server works because I've tested it with outlook, It has as name "localhost"
this is my function which sends mails:
Properties props = new Properties();
props.put("mail.debug", "true");
props.put("mail.smtp.host", "localhost");
Authenticator auth = new SMTPAuthentificator(); // class that return an authenticator with the correct username and password
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(true);
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
_____________________________________
and this is the error that i have:
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.SocketException: Software caused connection abort: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at com.Sender.sendMail(Sender.java:116)
at com.Sender.main(Sender.java:68)
Caused by: java.net.SocketException: Software caused connection abort: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1250)
... 8 more
_________________________________________________
Any idea please