• Register
0 votes

Problem :

I am facing below error every time :

javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
  nested exception is:
    java.net.ConnectException: Connection refused: connect
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1706)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:525)
    at javax.mail.Service.connect(Service.java:291)
    at javax.mail.Service.connect(Service.java:172)
    at javax.mail.Service.connect(Service.java:121)
    at javax.mail.Transport.send0(Transport.java:190)
    at javax.mail.Transport.send(Transport.java:120)
    at MailSendClass.main(MailSendClass.java:58)
Caused by: java.net.ConnectException: Connection refused: connect

I am unable to understand the error why this is happening to my code. Please let me know how to fix above error.

7 5 2
3,870 points

2 Answers

0 votes

Solution :

The Error you are getting is self explanatory: javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;

It seems you have no SMTP server on localhost, but you are configuring it there :

  // Assuming that you are sending the email from localhost

  String host = "localhost";


  // Setup the mail server

  properties.setProperty("mail.smtp.host", host);

So you must do below things:

· Either configure the local SMTP server as the relay on the local system (the Postfix or sendmail are the two very well knows servers)

· Or Configure the dummy server that simply traces your mail request but does not even try to deliver the mail (The Python is known to have such dummy servers out of a box)

· Or configure the application with the server that you are allowed to use so contact your system admin in your corporate environment, or the ISP in the individual one.

9 7 4
38,600 points
0 votes

When TDI 7.1.1 or SDI 7.2 uses the IBM JRE 7, then the following exception will appear. When either system.sendMail() or SendEMailFC are used to send emails.


One assembly line execution, the system.SendMail() produce the following error;

DEBUG SMTP: trying to connect to host "na.relay.ibm.com", port 25, isSSL false
CTGDIS399I Unable to send mail.Exception occurred: javax.mail.MessagingException: Could not connect to SMTP host: na.relay.ibm.com, port: 25;
nested exception is:
java.net.SocketException: Network is unreachable: connect

On AssemblyLine execution, the SendMailFC produces the following error;

javax.mail.MessagingException: Could not connect to SMTP host:, port: 25;
nested exception is:
java.net.SocketException: Network is unreachable: 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.ibm.di.fc.SendEMailFC.perform(SendEMailFC.java:519)
at com.ibm.di.server.AssemblyLineComponent.executeOperation(AssemblyLineComponent.java:3370)
at com.ibm.di.server.FunctionComponent.callreply(FunctionComponent.java:304)
at com.ibm.di.server.AssemblyLine.msExecuteNextConnector(AssemblyLine.java:3813)
at com.ibm.di.server.AssemblyLine.executeMainStep(AssemblyLine.java:3404)
at com.ibm.di.server.AssemblyLine.executeMainLoop(AssemblyLine.java:3012)
at com.ibm.di.server.AssemblyLine.executeMainLoop(AssemblyLine.java:2995)
at com.ibm.di.server.AssemblyLine.executeAL(AssemblyLine.java:2964)
at com.ibm.di.server.AssemblyLine.run(AssemblyLine.java:1328)
Caused by: java.net.SocketException: Network is unreachable: connect


It is possible that the IBM JVM is defaulting to the IPv6 protocol.

Resolving the error:

Implement the available options;

In solution.properties file, find, un-comment and set ‘java.net.preferIPv4Stack=true’


Call system.setProperty (“java.net.preferIPv$Stack”, “true”) before calling the system.sendMail()


In the SendEMailFC / After Initialize Hook, add system.setProperty(“java.net.preferIP4Stack”, “true”).

11 5 1
3,890 points

Related questions

0 votes
1 answer 419 views
Problem : I am facing below error message Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in I am unable to understand this message. Please let me know how can I fix it?
asked Jan 31 jwilliam 3.9k points
0 votes
1 answer 15 views
Problem Hi, PHPMailer is giving this error: SMTP Error: Could not connect to SMTP host. I tested sending mail from Thunderbird and it works. Yet, it fails on PHPMailer. Help needed.
asked Oct 28 hashq 1.1k points
1 vote
1 answer 212 views
Problem: I have fundamental knowledge in Spring Mvc 4. I have gained knowledge from local tutor. Now I am trying to use the javamail in the spring mvc 4 to send the email using the gmail but I am facing below error there. My error reads as: Info: DEBUG: getProvider( ... starttls.enable">true</prop>         </props>     </property> </bean> Please help me in fixing above error related to Spring MVC.
asked Jun 13 Martin K 6.6k points
0 votes
1 answer 20 views
Problem: I am a beginner to java, swing, netbeans and promise. Now I am trying to read and write the Extensible Linking Format (ELF). Please find below the line of code at which I am facing the Error: p = r.exec("./optimizer " + sourceFile + " ... .java:620) at java.lang.Runtime.exec(Runtime.java:450) at java.lang.Runtime.exec(Runtime.java:347) at GUIMode.GUIMode.actionPerformed(GUIMode.java:213)
asked Aug 26 Raphael Pacheco 4.9k points