添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
严肃的橡皮擦  ·  如果在SQL ...·  1 年前    · 
近视的菠萝  ·  为什么大多数的 C++ ...·  2 年前    · 
魁梧的小刀  ·  Node.js Sequelize ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am sending e email using an SMTP error . I am getting Authentication unsuccessful. The username and password are correct. Am I doing something wrong.

The error logs are

import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class EmailSender{
    public static void main(String args[]) {
        String to = "ssss@xxx.om";            // sender email
        String from = "dddd@xxx.com";       // receiver email
        String host = "dkdkdd.xxx.com";                   // mail server host
        String login="dkkdkd";
        String pass="dkkdkd";
       Properties properties = System.getProperties();
        properties.setProperty("mail.smtp.host", host);
        properties.setProperty("mail.smtp.user", login);
        properties.setProperty("mail.smtp.password", pass);
        properties.setProperty("mail.smtps.ssl.enable", "true");
       // properties.setProperty("mail.smtp.auth", "true"); 
        Session session = Session.getDefaultInstance(properties); // default session
        try {
            MimeMessage message = new MimeMessage(session);        // email message
            message.setFrom(new InternetAddress(from));                    // setting header fields
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            message.setSubject("Test Mail from Java Program"); // subject line
            // actual mail body
            message.setText("You can send mail from Java program by using");
            // Send message
            Transport transport = session.getTransport("smtp");
            transport.connect(host, login, pass);
            Transport.send(message);
            System.out.println("Email Sent successfully....");
        } catch (MessagingException mex) {
            mex.printStackTrace();

The error is

DEBUG SMTP: AUTH NTLM failed Exception in thread "main" javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful

at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:826)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685)
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)

Had the same issue. It's an MS Exchange error that you receive. You are probably not allowed to use your email to send an email via a relay. The administrator of the Exchange server needs to give the rights to do that.

It has nothing to do with a configuration problem on the Java side.

    emailPorperties = new Properties();
    emailPorperties.put("mail.smtp.host", "your host");
    emailPorperties.put("mail.smtp.socketFactory.port", "your port");
    emailPorperties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    emailPorperties.put("mail.smtp.auth", "true");
    emailPorperties.put("mail.smtp.port", "your port");
    emailPorperties.put("mail.smtp.ssl.enable", "true");
    emailSession = Session.getInstance(emailPorperties, new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                System.out.println("Authenticating");
                return new PasswordAuthentication(USER_NAME, PASSWORD);
                I already tried this, and I am getting same error ie                                    Exception in thread "main" javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful
– Mukesh Kumar
                Oct 21, 2015 at 4:47
                set the auth to true again...@MukeshKumar and add   props.setProperty("mail.smtp.starttls.enable", "true");
– ΦXocę 웃 Пepeúpa ツ
                Oct 21, 2015 at 6:48
                Thanks  a lot for your Prompt reply.  I added what you mentioned . I am getting error 220 2.0.0 SMTP server ready Exception in thread "main" javax.mail.MessagingException: Could not convert socket to TLS;  nested exception is: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1907)at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:666)
– Mukesh Kumar
                Oct 21, 2015 at 7:12
                I don't have any  SSL certificate of the mail server to be set and the mail server doesn't require too
– Mukesh Kumar
                Oct 21, 2015 at 7:22

Hello i've got the same issue in the past. So to solve it i have to connect on the webmail of my outlook or exchage and i noticed that these connexions were stopped by the server so inside i confirm that these transactions was mine. So u have also to do it usually every 2 month in my case.

The problem is not in the code. The problem occurs because something is wrong with the configuration of the mailboxes I believe.

I had a similar issue and in my case, the issue was 'outlook password got expired'. As I had it logged in default I did not have any issue while logging in to my mail.

I tried logging in to incognito mode and see if my logging asked for an additional layer for logging like multi-factor auth, And when logged in from the incognito tab it asked to change the password with a popup stating 'password got expired'.

I then updated the new password and it started to work fine !!

This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review – Dan May 9, 2022 at 19:28

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.