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

The Archive Base Latest Questions

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

I have this servlet which needs to send mail using Java Mail API, however

  • 0

I have this servlet which needs to send mail using Java Mail API, however I am getting no password specified error, although the password work with gmail.

MailServiceImpl.java:

public class MailServiceImpl extends RemoteServiceServlet implements MailService {

    private static String HOST = "smtp.gmail.com";
    private static int PORT = 465;
    private String username = "foo@gmail.com";
    private String password = "foo123"; 
    private Properties props = new Properties();

    @Override
    public void sendMail(String email) {
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true"); 

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

        Session session = Session.getInstance(props);
        try {
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("foo@gmail.com"));
            message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("foo@gmail.com"));
            message.setSubject("Testing Subject");
            message.setText("Subcriber Email:," +
                    "\n\n " + email);
            Transport transport = session.getTransport("smtp");
            transport.connect(HOST, PORT, username, password);
            Transport.send(message);            
            transport.close(); // -- needed?

        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

However I am getting this error:

javax.mail.AuthenticationFailedException: failed to connect, no password specified?
    at javax.mail.Service.connect(Service.java:329)
    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.mygwtapp.server.MailServiceImpl.sendMail(MailServiceImpl.java:43)
  • 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-24T10:22:20+00:00Added an answer on May 24, 2026 at 10:22 am

    Try using SSL connection. It worked for me.

        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        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");
    
        Session session = Session.getDefaultInstance(props,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication("username","password");
                }
            });
    
        try {
    
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("from@test.com"));
            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse("to@test.com"));
            message.setSubject("Testing Subject");
            message.setText("mail text");
    
            Transport.send(message);
    
            System.out.println("OK");
    
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a servlet which takes us to an existing jsp, say home.jsp. This
I have this java servlet that grabs information from a form, I need to
I have web services written using java which interacts with the android application only
Unix gurus! I have a Java program which passes some parameters to a Servlet
I have tested this servlet and it works well, except in Google Chrome it
I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the
I have a servlet that needs a call like http://localhost:8080?a=1&a=3&a=2&b=5 . The thing is
I'm trying to make this 2-player web game application using Spring MVC. I have
I have a servlet class which handles login. At the end of my login
The page works fine in Chrome, but I have this one minor error in

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.