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 9178409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:32:40+00:00 2026-06-17T17:32:40+00:00

I made a CLASSPATH environment variable binding jaf and javamail : name of user

  • 0

I made a CLASSPATH environment variable binding jaf and javamail :

name of user variable (windows): CLASSPATH

value of this variable: set CLASSPATH=%CLASSPATH%;C:\Java EE\Java SMTP\javamail-1.4.5\mail.jar;C:\Java EE\Java SMTP\jaf-1.1.1\activation.jar

I also put this 2 .jar files into my WebContent directory (into my java web application) and I add it to my buildpath.

I’m using Tomcat Apache Server 7.0.33.

Here is my servlet:

    @WebServlet (urlPatterns="/register")
    public class RegisterServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;

        private void sendMailRegistration(String email, int code)
                throws ServletException, IOException{
            Properties props = new Properties();
            Session session = Session.getDefaultInstance(props, null);

            String msgBody = "Here is the code you have to put for confirmation: "+Integer.toString(code);

            try {
                Message msg = new MimeMessage(session);
                msg.setFrom(new InternetAddress("dd@supinfo.com", "Admin SupLink"));
                msg.addRecipient(Message.RecipientType.TO,
                                 new InternetAddress(email, "User"));
                msg.setSubject("[SupLink] Activation");
                msg.setText(msgBody);
                Transport.send(msg);

            } catch (AddressException e) {
                e.printStackTrace();
            } catch (MessagingException e) {
               e.printStackTrace();
            }
        }

        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            String emailRegister = request.getParameter("emailRegister");
            int code = 1223;
                sendMailRegistration(emailRegister, code);

    }
}

and here is my error stacktrace:

    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:1972)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)
    at javax.mail.Service.connect(Service.java:295)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)
    at javax.mail.Transport.send0(Transport.java:194)
    at javax.mail.Transport.send(Transport.java:124)
    at com.supinfo.miniprojet.servlets.RegisterServlet.sendMailRegistration(RegisterServlet.java:43)
    at com.supinfo.miniprojet.servlets.RegisterServlet.doPost(RegisterServlet.java:81)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:319)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:233)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1938)
    ... 26 more

Someone know if there is a problem with my source mail address : dd@supinfo.com, or my CLASSPATH, because I just took Google implementation exemple here Google java mail ?

  • 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-17T17:32:41+00:00Added an answer on June 17, 2026 at 5:32 pm

    You need to identify a mail server to use (as you’re obviously not running one on the localhost). Once identified, you need to configure Java Mail to use it. You can refer to the code below as an example of utilizing Google Mail servers:

    public static void main(String[] args) {
    
        final String username = "username@gmail.com";
        final String password = "password";
    
        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.port", "587");
    
        Session session = Session.getInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(username, password);
                    }
                });
    
        try {
    
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("from-email@gmail.com"));
            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse("to-email@gmail.com"));
            message.setSubject("Testing Subject");
            message.setText("Dear Mail Crawler,"
                    + "\n\n No spam to my email, please!");
    
            Transport.send(message);
    
            System.out.println("Done");
    
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
    

    Note: This is not my code, you can reference the complete examples here

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

Sidebar

Related Questions

Made correction to previous errors, this error now comes up. C:\Documents and Settings\AdminUser\My Documents\InventoryPart3.java:93:
Made this nice little loop for hiding and showing div's, works as a charm
I made an iphone app to capture image from camera and to set that
I have written a Java applet class and made a small HTML page to
I got stuck right now. Firstly i made Java application that i run from
I work with many small, but unrelated java projects. I made an Ant script
I have run the following code in this page RsyntaxTextArea using Java and i
So, I'm working from this example BONECP : package javasampleapps; import java.sql.Connection; import java.sql.ResultSet;
i have made an installer with izpack for my java desktop application ... after
Java Service Wrapper is the tools I need to run as a Windows service

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.