Email 邮件:com.sun.Mail.smtp.SMTPSendFailedException:530 5.7.1需要身份验证

Email 邮件:com.sun.Mail.smtp.SMTPSendFailedException:530 5.7.1需要身份验证,email,jakarta-mail,Email,Jakarta Mail,我正在尝试从我的Java应用程序向任何特定的电子邮件地址发送电子邮件。我正在使用JavaMail API,但不幸的是,我得到了SMTPSendFailedException错误。谁能告诉我哪里出了错。这是我的密码 Properties properties = new Properties(); properties.put("mail.smtp.host", "plus.smtp.mail.yahoo.com"); properties.put("mail.smtp.p

我正在尝试从我的Java应用程序向任何特定的电子邮件地址发送电子邮件。我正在使用JavaMail API,但不幸的是,我得到了SMTPSendFailedException错误。谁能告诉我哪里出了错。这是我的密码

    Properties properties = new Properties();
    properties.put("mail.smtp.host", "plus.smtp.mail.yahoo.com");
    properties.put("mail.smtp.port", "587");
    properties.put("mail.smtp.starttls.enable", "true");
    properties.put("mail.smtp.user", emailId);
    properties.put("mail.smtp.password", password);

    Session emailSession = Session.getDefaultInstance(properties,
            new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(emailId,password);
                }
            });
    emailSession.setDebug(true);

    try {
        MimeMessage message = new MimeMessage(emailSession);
        message.setFrom(new InternetAddress(from));
        message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
        message.setSubject("Ping");
        message.setText("Hello, this is example of sending email  ");

        // Send message
        Transport.send(message);
        System.out.println("message sent successfully....");

    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }
当我运行此代码时,我得到:

DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "plus.smtp.mail.yahoo.com", port 587, isSSL false
220 *.smtp.mail.yahoo.com ESMTP ready
DEBUG SMTP: connected to host "plus.smtp.mail.yahoo.com", port: 587

EHLO Libsys-PC
250-*.smtp.mail.yahoo.com
250-PIPELINING
250-SIZE 41697280
250-8 BITMIME
250 XXXXXXXX
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "41697280"
DEBUG SMTP: Found extension "8", arg "BITMIME"
DEBUG SMTP: Found extension "XXXXXXXX", arg ""
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "plus.smtp.mail.yahoo.com", port 587, isSSL false
220 *.smtp.mail.yahoo.com ESMTP ready
DEBUG SMTP: connected to host "plus.smtp.mail.yahoo.com", port: 587

EHLO Libsys-PC
250-*.smtp.mail.yahoo.com
250-PIPELINING
250-SIZE 41697280
250-8 BITMIME
250 XXXXXXXX
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "41697280"
DEBUG SMTP: Found extension "8", arg "BITMIME"
DEBUG SMTP: Found extension "XXXXXXXX", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:from
530 5.7.1 Authentication required
DEBUG SMTP: got response code 530, with response: 530 5.7.1 Authentication required

RSET
250 2.0.0 OK
DEBUG SMTP: MessagingException while sending, THROW: 
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Authentication required

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
    at javax.mail.Transport.send0(Transport.java:195)
    at javax.mail.Transport.send(Transport.java:124)
    at Mail.main(Mail.java:119)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
QUIT
221 2.0.0 Bye
Exception in thread "main" java.lang.RuntimeException: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Authentication required

    at Mail.main(Mail.java:123)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Authentication required

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
    at javax.mail.Transport.send0(Transport.java:195)
    at javax.mail.Transport.send(Transport.java:124)
    at Mail.main(Mail.java:119)
    ... 5 more

    Process finished with exit code 1
     Properties properties = new Properties();
    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 emailSession = Session.getInstance(properties);
    emailSession.setDebug(true);

    //create the POP3 store object and connect with the pop server
    try {

        MimeMessage message = new MimeMessage(emailSession);
        message.setFrom(new InternetAddress(from));
        message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
        message.setSubject("Ping");
        message.setText("Hello, this is example of sending email  ");
        Transport.send(message,id,password);

        System.out.println("message sent successfully....");

    } catch (MessagingException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
:

反映我的代码后是:

DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "plus.smtp.mail.yahoo.com", port 587, isSSL false
220 *.smtp.mail.yahoo.com ESMTP ready
DEBUG SMTP: connected to host "plus.smtp.mail.yahoo.com", port: 587

EHLO Libsys-PC
250-*.smtp.mail.yahoo.com
250-PIPELINING
250-SIZE 41697280
250-8 BITMIME
250 XXXXXXXX
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "41697280"
DEBUG SMTP: Found extension "8", arg "BITMIME"
DEBUG SMTP: Found extension "XXXXXXXX", arg ""
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "plus.smtp.mail.yahoo.com", port 587, isSSL false
220 *.smtp.mail.yahoo.com ESMTP ready
DEBUG SMTP: connected to host "plus.smtp.mail.yahoo.com", port: 587

EHLO Libsys-PC
250-*.smtp.mail.yahoo.com
250-PIPELINING
250-SIZE 41697280
250-8 BITMIME
250 XXXXXXXX
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "41697280"
DEBUG SMTP: Found extension "8", arg "BITMIME"
DEBUG SMTP: Found extension "XXXXXXXX", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:from
530 5.7.1 Authentication required
DEBUG SMTP: got response code 530, with response: 530 5.7.1 Authentication required

RSET
250 2.0.0 OK
DEBUG SMTP: MessagingException while sending, THROW: 
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Authentication required

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
    at javax.mail.Transport.send0(Transport.java:195)
    at javax.mail.Transport.send(Transport.java:124)
    at Mail.main(Mail.java:119)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
QUIT
221 2.0.0 Bye
Exception in thread "main" java.lang.RuntimeException: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Authentication required

    at Mail.main(Mail.java:123)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Authentication required

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
    at javax.mail.Transport.send0(Transport.java:195)
    at javax.mail.Transport.send(Transport.java:124)
    at Mail.main(Mail.java:119)
    ... 5 more

    Process finished with exit code 1
     Properties properties = new Properties();
    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 emailSession = Session.getInstance(properties);
    emailSession.setDebug(true);

    //create the POP3 store object and connect with the pop server
    try {

        MimeMessage message = new MimeMessage(emailSession);
        message.setFrom(new InternetAddress(from));
        message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
        message.setSubject("Ping");
        message.setText("Hello, this is example of sending email  ");
        Transport.send(message,id,password);

        System.out.println("message sent successfully....");

    } catch (MessagingException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
但调试输出和前面的相同

    DEBUG: setDebug: JavaMail version 1.5.5
 DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
220 smtp.gmail.com ESMTP i62sm9706430pfg.62 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 587

EHLO Libsys-PC
250-smtp.gmail.com at your service, [163.47.140.139]
250-SIZE 35882577
250-8BITMIME
250-ENHANCEDSTATUSCODES
250-PIPELINING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<rohitsingla6@gmail.com>
530 5.7.0 Must issue a STARTTLS command first. i62sm9706430pfg.62 - gsmtp
DEBUG SMTP: got response code 530, with response: 530 5.7.0 Must issue a STARTTLS command first. i62sm9706430pfg.62 - gsmtp

RSET
250 2.1.5 Flushed i62sm9706430pfg.62 - gsmtp
DEBUG SMTP: MessagingException while sending, THROW: 
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. i62sm9706430pfg.62 - gsmtp

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2249)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1740)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1239)
    at javax.mail.Transport.send0(Transport.java:255)
    at javax.mail.Transport.send(Transport.java:174)
    at GMail.main(GMail.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
QUIT
221 2.0.0 closing connection i62sm9706430pfg.62 - gsmtp
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. i62sm9706430pfg.62 - gsmtp

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2249)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1740)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1239)
    at javax.mail.Transport.send0(Transport.java:255)
    at javax.mail.Transport.send(Transport.java:174)
    at GMail.main(GMail.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Exception in thread "main" java.lang.RuntimeException: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. i62sm9706430pfg.62 - gsmtp

    at GMail.main(GMail.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. i62sm9706430pfg.62 - gsmtp

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2249)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1740)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1239)
    at javax.mail.Transport.send0(Transport.java:255)
    at javax.mail.Transport.send(Transport.java:174)
    at GMail.main(GMail.java:32)
    ... 5 more
DEBUG:setDebug:JavaMail版本1.5.5
调试:getProvider()返回javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
调试SMTP:useEhlo true,useAuth true
调试SMTP:尝试连接到主机“SMTP.gmail.com”,端口587,isSSL false
220 smtp.gmail.com ESMTP i62sm9706430pfg.62-gsmtp
调试SMTP:已连接到主机“SMTP.gmail.com”,端口:587
EHLO Libsys PC
250-smtp.gmail.com,随时为您服务,[163.47.140.139]
250号35882577
250-8比特
250-增强状态码
250-流水线
250 SMTPUTF8
调试SMTP:找到扩展名“大小”,参数“35882577”
调试SMTP:找到扩展名“8BITMIME”,参数“”
调试SMTP:找到扩展名“ENHANCEDSTATUSCODES”,arg“”
调试SMTP:找到扩展名“管道”,arg“”
调试SMTP:找到扩展名“SMTPUTF8”,arg“”
调试SMTP:use8bit false
邮寄地址:
530 5.7.0必须首先发出STARTTLS命令。i62sm9706430pfg.62-gsmtp
调试SMTP:Get响应代码530,响应为530 5.7.0必须首先发出STARTTLS命令。i62sm9706430pfg.62-gsmtp
RSET
250 2.1.5冲洗式i62sm9706430pfg.62-gsmtp
发送时调试SMTP:MessaginException,引发:
com.sun.mail.smtp.SMTPSendFailedException:530 5.7.0必须首先发出STARTTLS命令。i62sm9706430pfg.62-gsmtp
在com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2249)上
在com.sun.mail.smtp.SMTPTransport.mailFrom上(SMTPTransport.java:1740)
在com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1239)上
位于javax.mail.Transport.send0(Transport.java:255)
在javax.mail.Transport.send(Transport.java:174)
在GMail.main(GMail.java:32)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)中
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:606)
位于com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
退出
221 2.0.0闭合连接i62sm9706430pfg.62-gsmtp
com.sun.mail.smtp.SMTPSendFailedException:530 5.7.0必须首先发出STARTTLS命令。i62sm9706430pfg.62-gsmtp
在com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2249)上
在com.sun.mail.smtp.SMTPTransport.mailFrom上(SMTPTransport.java:1740)
在com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1239)上
位于javax.mail.Transport.send0(Transport.java:255)
在javax.mail.Transport.send(Transport.java:174)
在GMail.main(GMail.java:32)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)中
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:606)
位于com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
线程“main”java.lang.RuntimeException:com.sun.mail.SMTPSendFailedException:530 5.7.0中的异常必须首先发出STARTTLS命令。i62sm9706430pfg.62-gsmtp
在GMail.main(GMail.java:38)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)中
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:606)
位于com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
原因:com.sun.mail.smtp.SMTPSendFailedException:530 5.7.0必须首先发出STARTTLS命令。i62sm9706430pfg.62-gsmtp
在com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2249)上
在com.sun.mail.smtp.SMTPTransport.mailFrom上(SMTPTransport.java:1740)
在com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1239)上
位于javax.mail.Transport.send0(Transport.java:255)
在javax.mail.Transport.send(Transport.java:174)
在GMail.main(GMail.java:32)
... 还有5个
您应该检查并修复这些问题;特别是,您应该去掉验证器并使用。如果无法升级,请将属性
mail.smtp.auth
设置为
“true”
。而且没有
mail.smtp.password
属性,所以不必费心设置它。

您应该检查并修复这些属性;特别是,您应该去掉验证器并使用。如果无法升级,请将属性
mail.smtp.auth
设置为
“true”
。而且没有
mail.smtp.password
属性,所以不用麻烦设置它。

  • 在JAVA Mail API中,您必须按照JAVA Mail API的文档设置用户名和发件人地址。因此,

  • 这两个句子在您的代码中应该是这样的,无论何时 正在使用JAVA Mail API

    properties.put(“mail.smtp.user”,emailId)

    message.setFrom(新的InternetAddress(emailId))

      • 在JAVA Mail API中,您必须按照JAVA Mail API的文档设置用户名和发件人地址。因此,

      • 这两个句子在您的代码中应该是这样的,无论何时 正在使用JAVA Mail API

        properties.put(“mail.smtp.user”,emailId)

        message.setFrom(新的InternetAddress(emailId))


      您好,正如您所说,我已经更改了代码,但仍然会出现相同的错误。有没有可能是防火墙阻止了它。因为当我从另一个s运行这个