Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8034597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:04:24+00:00 2026-06-05T02:04:24+00:00

My code is : // File Name SendEmail.java import java.util.*; import javax.mail.*; import javax.mail.internet.*;

  • 0

My code is :

// File Name SendEmail.java

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendEmail
{
   public static void main(String [] args)
   {

      // Recipient's email ID needs to be mentioned.
      String to = "toEmail@gmail.com";

      // Sender's email ID needs to be mentioned
      String from = "fromEmail@gmail.com";

      // Assuming you are sending email from localhost
      String host = "localhost";

      // Get system properties
      Properties properties = System.getProperties();

      // Setup mail server
      properties.setProperty("mail.smtp.host", host);

      // Get the default Session object.
      Session session = Session.getDefaultInstance(properties);

      try{
         // Create a default MimeMessage object.
         MimeMessage message = new MimeMessage(session);

         // Set From: header field of the header.
         message.setFrom(new InternetAddress(from));

         // Set To: header field of the header.
         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));

         // Set Subject: header field
         message.setSubject("This is the Subject Line!");

         // Now set the actual message
         message.setText("This is actual message");

         // Send message
         Transport.send(message);
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }
}

My program was working correctly last night; I could send email from any address to any other, but now this error is occuring:

javax.mail.SendFailedException: Sending failed;
  nested exception is:
    class javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
  nested exception is:
    java.net.ConnectException: Connection refused
    at javax.mail.Transport.send0(Transport.java:218)
    at javax.mail.Transport.send(Transport.java:80)
    at SendEmail.main(SendEmail.java:49)

Line 49 is:

Transport.send(message);

Can anyone help me fix this error?

My operating system is : Linux,Fedora 16 -kernel: 3.3.7

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:04:25+00:00Added an answer on June 5, 2026 at 2:04 am

    Could not connect to SMTP host: localhost, port: 25;

    SMTP must be not running on your system or disabled for you as user. Check with your system administrator and get it enabled for you.

    To check if SMTP is working on your Linux system, try the following commands:

    1. To simply verify Sendmail is running, try: netstat -an | grep 25
    2. Use telnet to connect to port 25 of smtp server: telnet <yourhost-or-ipnumber> 25
      a. Connecting To localhost…Could not open connection to the host, on port 25: Connect failed.
      b. if you or your ip is blocked, you would see error message something like this:
      220-localhost ESMTP Exim 4.63 #1 Fri, 01 Jun 2012 19:35:30 +0530
      220-We do not authorize the use of this system to transport unsolicited, and/or bulk e-mail.
    3. echo -e "quit" | nc localhost 25
      localhost.localdomain [127.0.0.1] 25 (?) : Connection refused
    4. mail at shell prompt.
    5. and, may be more…

    You should check that sendmail daemon is started and is available always.

    And if you have access to any other SMTP servers, try to send mail using their SMTP host name, to check if your code snippet is working.
    Example : String host = "smtp.gmail.com";

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the code below the file name is hard coded, but I want the
The code to print the file name is <div id=file>'+filename+'</div> i want only the
I have some source code to get the file name of an url for
I have written a following code to get just the file name without extension
How can I retrieve the XML source file name using XSL 1.0 code?
I want to extract just the file name portion of a path. My code
I tried this aproach without any success the code I'm using: // File name
I have the following code in a .erb file: <% embed='<a href=http://someurl.com/whatever>#{@webcast.name}</a>'%> <p id=embedCode>
I writte this code to send multiple attachments: $tablica_plikow=$_FILES[file]; //array of files if(!empty($tablica_plikow['name'])){///if attachment
The following Java code is used to attach a file to an email. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.