• Register
0 votes
1.4k views

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

Please log in or register to answer this question.

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.

Symptoms:

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: 10.10.10.1, 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

Causes:

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’

Or

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

Or

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

11 5 2
3,890 points

Related questions

0 votes
1 answer 25 views
25 views
Can anybody help me out with this issue?
asked Jan 3 TeamScript 13.5k points
0 votes
1 answer 12 views
12 views
Problem: This mistake is happening sporadically and I was unable to discover the main driver of this issue. plz, help me out of this issue.
asked 6 days ago TeamScript 13.5k points
0 votes
1 answer 5 views
5 views
Problem: Unable to reset user password from within the Web UI due to specific error messages in the log file: 1. Could not convert socket to TLS. 2. Unable to find valid certification path to requested target.
asked Feb 5 Ali 4.3k points
0 votes
1 answer 11 views
11 views
Help me to solve this.
asked Jan 22 TeamScript 13.5k points
0 votes
1 answer 14 views
14 views
Please help me to resolve this.
asked Jan 22 TeamScript 13.5k points
0 votes
1 answer 622 views
622 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, 2020 jwilliam 3.9k points
0 votes
0 answers 4 views
4 views
javax.mail.messagingexception: could not convert socket to tls
asked Feb 16 ArifulIslam 7.5k points
0 votes
1 answer 34 views
34 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, 2020 hashq 1.1k points