• Register
0 votes
1.7k 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 27 views
27 views
Problem: I am facing below error every time :Javax.mail.messagingexception: could not connect to smtp host: localhost, port: 25, response: 421.
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
1 answer 37 views
37 views
Can anybody help me out with this issue?
asked Jan 3 TeamScript 13.5k points
0 votes
1 answer 23 views
23 views
Problem: Hi could some one fix this? javax.mail.messagingexception could not convert socket to tls
asked Mar 20 PkGuy 23.5k points
0 votes
1 answer 14 views
14 views
Problem: When I encountered this problem, I attempted to find a solution on the internet but was unable to find any useful details. If you read the above query and understand what the solution is, please cooperate with me- Thanks.
asked Apr 1 rakib1 51.5k points
0 votes
1 answer 10 views
10 views
Problem: I'm having trouble processing this error: It is required that the operation be exported or include an intent-filter of Could not open connection to the host on port 23 connect failed windows 10.
asked Apr 1 rakib1 51.5k points
0 votes
1 answer 25 views
25 views
Problem: When I encountered this problem, I attempted to find a solution on the internet but was unable to find any useful details. If you read the above query and understand what the solution is, please cooperate with me- Thanks.
asked Apr 1 rakib1 51.5k points
0 votes
1 answer 19 views
19 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 Feb 17 TeamScript 13.5k points
0 votes
1 answer 12 views
12 views
Problem: Can anyone please justify it with the simplest > Javax.mail.messagingexception: could not connect to smtp host: smtp.gmail.com, port: 465
asked Apr 24 ummeshani 10.8k points
0 votes
1 answer 26 views
26 views
Problem: javax.mail.messagingexception: could not connect to smtp host: smtp.gmail.com, port: 465;
asked Feb 23 Muneeb Saadii 130k points
0 votes
1 answer 16 views
16 views
Help me to solve this.
asked Jan 22 TeamScript 13.5k points