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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:10:22+00:00 2026-05-24T09:10:22+00:00

i am trying the below example to send mail using ssl picked from here

  • 0

i am trying the below example to send mail using ssl picked from here and changed with my credentials as below and get exception as shown, can you please help me to get through it

import javax.mail.*;
import javax.mail.internet.*;

import java.util.Properties;


public class SimpleSSLMail {

    private static final String SMTP_HOST_NAME = "xx.xx.xx.xx";
    private static final int SMTP_HOST_PORT = 25 ;//465;
    private static final String SMTP_AUTH_USER = "xxx@yyy.com";
    private static final String SMTP_AUTH_PWD  = "xxxx";

    public static void main(String[] args) throws Exception{
       new SimpleSSLMail().test();
    }

    public void test() throws Exception{
        Properties props = new Properties();

        props.put("mail.transport.protocol", "smtps");
        props.put("mail.smtps.host", SMTP_HOST_NAME);
        props.put("mail.smtps.auth", "true");
        // props.put("mail.smtps.quitwait", "false");

        Session mailSession = Session.getDefaultInstance(props);
        mailSession.setDebug(true);
        Transport transport = mailSession.getTransport();

        MimeMessage message = new MimeMessage(mailSession);
        message.setSubject("Testing SMTP-SSL");
        message.setContent("This is a test", "text/plain");

        message.addRecipient(Message.RecipientType.TO,
             new InternetAddress("myid@gmail.com"));

        transport.connect
          (SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);

        transport.sendMessage(message,
            message.getRecipients(Message.RecipientType.TO));
        transport.close();
    }
}

Exception:

Exception in thread "main" javax.mail.MessagingException: Could not connect to SMTP host:xx.xx.xx.xx, port: 25;
  nested exception is:
    java.net.ConnectException: Connection timed out: 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)
  • 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-05-24T09:10:23+00:00Added an answer on May 24, 2026 at 9:10 am

    This type of problem occurs due to a network problem . May be you require authentication, you may have wrong username , password .

    Anyways you are missing in a lot of things in your code.
    Example to obtain a proper SSL connection with gmail server

    props.put("mail.smtp.socketFactory.port", "465");
     props.put("mail.smtp.socketFactory.class",
                               "javax.net.ssl.SSLSocketFactory");
     props.put("mail.smtp.auth", "true");
     props.put("mail.smtp.port", "465");
    

    I don’t see this any where in your code. Then where is the method to authenticate ?

    Just check out the following links :

    Sending E-mail Using Gmail In Java Here you have a choice of using TLS or SSl

    Java Mail API

    E-mailing through Java

    keys used in java mailing system for your reference

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

Sidebar

Related Questions

I am using the KbFilter example in the WDK, trying to send an IOCTL
I am trying to send an email via GMail from ASP.Net using the code
I'm very new to Mocking. In the below example i'm using Moq and trying
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
In the example below I'm trying to access the parents sibling. Is there a
I'm trying to perform a group by action on an aliased column (example below)
Below I have a very simple example of what I'm trying to do. I
The code below is what I am trying to use in order to get
Below is my program and I am trying to get the call stack when
I'm trying to call the SQL statement below but get the following error: System.Data.SqlClient.SqlException:

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.