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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:46:48+00:00 2026-05-28T07:46:48+00:00

I am using the following code for sending e-mail (gmail) using Java program. I

  • 0

I am using the following code for sending e-mail (gmail) using Java program. I am getting the AuthenticationFailedException. I mentioned the error below. How to solve this? How to use sender username ,password in this program ?

        package internet;

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

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


              String to = "xxx@gmail.com";
              String from = "yyy@gmail.com";


              String host = "smtp.gmail.com";


              Properties properties = System.getProperties();


              properties.put("mail.smtp.host", "smtp.gmail.com");
              properties.put("mail.smtp.port", "587");
              properties.put("mail.smtp.auth", "true");
              properties.put("mail.smtp.starttls.enable", "true");



              Session session = Session.getDefaultInstance(properties);

              try{

                 MimeMessage message = new MimeMessage(session);


                 message.setFrom(new InternetAddress(from));


                 message.addRecipient(Message.RecipientType.TO,
                                          new InternetAddress(to));


                 message.setSubject("This is the Subject Line!");


                 message.setText("This is actual message");


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

I have get the following error

    javax.mail.AuthenticationFailedException
            at javax.mail.Service.connect(Service.java:267)
            at javax.mail.Service.connect(Service.java:137)
            at javax.mail.Service.connect(Service.java:86)
            at javax.mail.Transport.send0(Transport.java:150)
            at javax.mail.Transport.send(Transport.java:80)
            at internet.mail.main(mail.java:59)
  • 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-28T07:46:49+00:00Added an answer on May 28, 2026 at 7:46 am

    You have to provide your login credentials with t.connect(host, user, password) prior to t.sendMessage(message, addresses). (Aquire a Transport object first with Transport t = session.getTransport("smtp").

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

Sidebar

Related Questions

I'm using the following code from this answer Sending email in .NET through Gmail
I am running into the following error using Pear Mail: Notice: Error in sending
I am using the following very simple code and I keep getting System.Net.Mail.SmtpException failure
I have a server sending me this response. However, using the following code I
I'm using following code but cannot return data from MySQL. This is the output:
I am sending emails successfully using following code. But now I want to attach
I'm using the following piece of code in Android to send a mail: Intent
I am sending file using following code in my android application : Intent intent
The following code gives me this error: Cannot convert from 'System.Collections.Generic.List' to 'System.Collections.Generic.List'. How
i am sending email through my application using the following code of c# myMail.Body

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.