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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:15:26+00:00 2026-06-09T21:15:26+00:00

I am trying out an email app on android.I take the username and password

  • 0

I am trying out an email app on android.I take the username and password first
then on the next activity i take the recipiend address subject and msg and send the email.
I get the error JavaX authentication failure.Here is my Mail authentication and sending code.OnClick function of the send button calls this class

public class MailHandler {
final String username;
final String password;
public MailHandler(String username,String password){
    this.username=username;
    this.password=password;

}

public void sendMail(String Sub,String msg,String sender,String cc,String to) {
    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(sender));
        message.setRecipients(Message.RecipientType.TO,
            InternetAddress.parse(to));
        message.setSubject(Sub);
        message.setText(msg);

        Transport.send(message);

        System.out.println("Done");

    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }
}
}
  • 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-09T21:15:27+00:00Added an answer on June 9, 2026 at 9:15 pm

    Your code works. I copied it compiled and ran it using my gmail credentials. Are you sure you are using the correct gmail credentials for sending mail?

    MailHandler m = new MailHandler("myAccount@gmail.com", "myPassword");
    m.sendMail("Test", "Testing", "myOtherAccount@gmail.com", "myWork@myCompany.com", "myOtherWork@myCompany.com");
    

    // After running I checked my work email and saw the message.

    If I use an invalid password I get the following statcktrace. Is this what you are seeing

    535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 jl8sm4152932obb.18
    
        at MailHandler.sendMail(MailHandler.java:50)
            at MailHandler.main(MailHandler.java:56)
    Caused by: javax.mail.AuthenticationFailedException: 535-5.7.1 Username and Password not accepted. Learn more at
    535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 jl8sm4151848obb.18
        at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:823)
        at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:756)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:673)
        at javax.mail.Service.connect(Service.java:317)
        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 MailHandler.sendMail(MailHandler.java:45)
        ... 1 more
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to work out how I can request a Facebook user's email address
in my app i am trying to send an email and password to an
Hello I have been trying to send an email in magento with out a
I can't figure out where I'm going wrong here. Trying to validate an email
I am trying to implement email functionality in my app but I keep getting
I am trying to implement a Codeigniter based app on Android via phonegap, all
I'm trying to send an email from AppController in my CakePHP 2.0 app. It
I am trying out seeds.rb for the first time, and one of my data
I am trying to make a metro app which involves the user sending out
I'm trying to figure out how to verify that the user purchased my app

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.