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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:58:27+00:00 2026-06-07T02:58:27+00:00

I am not able to send email from my yahoo id using Java mail

  • 0

I am not able to send email from my yahoo id using Java mail API. I tried different options from Google,but fails. Please have a look my below code and let me know if I am missing something. In my point of view Yahoo does not provide the free service to send mails, but I am not sure. Please provide your thoughts on this.

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

public class MailExample {
    private static final String SMTP_HOST_NAME = "smtp.mail.yahoo.com";
    private static final int SMTP_HOST_PORT = 587;//465,587,25
    private static final String SMTP_AUTH_USER = "dummyrls@yahoo.com";
    private static final String SMTP_AUTH_PWD  = "my password";

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

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

        props.put("mail.transport.protocol", "smtp");
        props.put("mail.smtp.host", SMTP_HOST_NAME);
        props.put("mail.smtp.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("rlss@abc.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();
    }
}

The above code works fine for Gmail, but for Yahoo it’s giving error like:

DEBUG: setDebug: JavaMail version 1.4.1 DEBUG: getProvider() 
  returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,
  Sun Microsystems, Inc.,1.4.1] DEBUG SMTP: useEhlo true, 
  useAuth true 
DEBUG SMTP: trying to connect to host "smtp.mail.yahoo.com", port 587, 
  isSSL false Exception in thread "main" 
javax.mail.MessagingException: Could not connect to SMTP 
  host: smtp.mail.yahoo.com, port: 587;   nested exception is:  
java.net.ConnectException: Connection timed out: connect    
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)  
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)  
at javax.mail.Service.connect(Service.java:288)     
at com.sample.mailexample.MailExample.test(MailExample.java:313)    
at com.sample.mailexample.MailExample.main(MailExample.java:291) Caused by: 
   java.net.ConnectException: Connection timed out: connect     
at java.net.PlainSocketImpl.socketConnect(Native Method)    
at java.net.PlainSocketImpl.doConnect(Unknown Source)   
at java.net.PlainSocketImpl.connectToAddress(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:233)     
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)    
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)  
... 4 more

How can I solve this?

  • 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-07T02:58:29+00:00Added an answer on June 7, 2026 at 2:58 am

    Try this code

    public class SendMail {
    
        String host, port, emailid,username, password;
        Properties props = System.getProperties();
        Session l_session = null;
    
        public BSendMail() {
            host = "smtp.mail.yahoo.com";
            port = "587";
            emailid = "a@yahoo.com";
            username = "a";
            password = "pwd";
    
            emailSettings();
            createSession();
            sendMessage("a@yahoo.com", "rahul@gmail.com","Test","test Mail");
        }
    
        public void emailSettings() {
            props.put("mail.smtp.host", host);
            props.put("mail.smtp.auth", "true");
            props.put("mail.debug", "false");
            props.put("mail.smtp.port", port);
    //        props.put("mail.smtp.socketFactory.port", port);
    //        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    //        props.put("mail.smtp.socketFactory.fallback", "false");
    
        }
    
        public void createSession() {
    
            l_session = Session.getInstance(props,
                    new javax.mail.Authenticator() {
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(username, password);
                        }
                    });
    
            l_session.setDebug(true); // Enable the debug mode
    
        }
    
        public boolean sendMessage(String emailFromUser, String toEmail, String subject, String msg) {
            //System.out.println("Inside sendMessage 2 :: >> ");
            try {
                //System.out.println("Sending Message *********************************** ");
                MimeMessage message = new MimeMessage(l_session);
                emailid = emailFromUser;
                //System.out.println("mail id in property ============= >>>>>>>>>>>>>> " + emailid);
                //message.setFrom(new InternetAddress(emailid));
                message.setFrom(new InternetAddress(this.emailid));
    
                message.addRecipient(Message.RecipientType.TO, new InternetAddress(toEmail));
                message.addRecipient(Message.RecipientType.BCC, new InternetAddress(AppConstants.fromEmail));
                message.setSubject(subject);
                message.setContent(msg, "text/html");
    
                //message.setText(msg);
                Transport.send(message);
                System.out.println("Message Sent");
            } catch (MessagingException mex) {
                mex.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }//end catch block
            return true;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am successfully able to send email using the smtplib module. But when the
I need to be able to send an email from a silverlight client-side application.
I am able to send email to one email id by defining the id
We use Google Apps (Gmail) to send and receive all of our email. Our
I wrote a small email sending program in java, it has from , to
I have an application that uses SmtpClient to send E-Mail, but the E-Mails are
I am using SwiftMailer to send emails from my application. All is working fine
On GAE, a non-gmail user can create a Google Account using their non-gmail email
I'm using tomcat 7 and Spring 3.0.5 and I'm trying to send email using
I have used this code to send mails but I am not getting any

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.