<bdo id='o5tR1'></bdo><ul id='o5tR1'></ul>
<legend id='o5tR1'><style id='o5tR1'><dir id='o5tR1'><q id='o5tR1'></q></dir></style></legend>

  • <tfoot id='o5tR1'></tfoot>
    <i id='o5tR1'><tr id='o5tR1'><dt id='o5tR1'><q id='o5tR1'><span id='o5tR1'><b id='o5tR1'><form id='o5tR1'><ins id='o5tR1'></ins><ul id='o5tR1'></ul><sub id='o5tR1'></sub></form><legend id='o5tR1'></legend><bdo id='o5tR1'><pre id='o5tR1'><center id='o5tR1'></center></pre></bdo></b><th id='o5tR1'></th></span></q></dt></tr></i><div id='o5tR1'><tfoot id='o5tR1'></tfoot><dl id='o5tR1'><fieldset id='o5tR1'></fieldset></dl></div>

        <small id='o5tR1'></small><noframes id='o5tR1'>

        javax.mail.AuthenticationFailedException:连接失败,没有指定密码?

        javax.mail.AuthenticationFailedException: failed to connect, no password specified?(javax.mail.AuthenticationFailedException:连接失败,没有指定密码?)

        <tfoot id='nfGQA'></tfoot>

        1. <small id='nfGQA'></small><noframes id='nfGQA'>

            <bdo id='nfGQA'></bdo><ul id='nfGQA'></ul>
          • <legend id='nfGQA'><style id='nfGQA'><dir id='nfGQA'><q id='nfGQA'></q></dir></style></legend>

          • <i id='nfGQA'><tr id='nfGQA'><dt id='nfGQA'><q id='nfGQA'><span id='nfGQA'><b id='nfGQA'><form id='nfGQA'><ins id='nfGQA'></ins><ul id='nfGQA'></ul><sub id='nfGQA'></sub></form><legend id='nfGQA'></legend><bdo id='nfGQA'><pre id='nfGQA'><center id='nfGQA'></center></pre></bdo></b><th id='nfGQA'></th></span></q></dt></tr></i><div id='nfGQA'><tfoot id='nfGQA'></tfoot><dl id='nfGQA'><fieldset id='nfGQA'></fieldset></dl></div>
              <tbody id='nfGQA'></tbody>

                • 本文介绍了javax.mail.AuthenticationFailedException:连接失败,没有指定密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  此程序尝试发送电子邮件但抛出运行时异常:

                  This program attempts to send e-mail but throws a run time exception:

                  javax.mail.AuthenticationFailedException: failed to connect, no password specified?
                  

                  当我提供了正确的用户名和密码进行身份验证时,为什么会出现此异常?

                  Why am I getting this exception when I have supplied the correct username and password for authentication?

                  发件人和收件人都有 g-mail 帐户.发件人和收件人都有 g-mail 帐户.发件人已禁用两步验证过程.

                  Both the sender and receiver have g-mail accounts. The sender and the receiver both have g-mail accounts. The sender has 2-step verification process disabled.

                  这是代码:

                  import javax.mail.*;
                  import javax.mail.internet.*;
                  import java.util.*;
                  
                  class tester {
                      public static void main(String args[]) {
                          Properties props = new Properties();
                          props.put("mail.smtp.host" , "smtp.gmail.com");
                          props.put("mail.stmp.user" , "username");
                  
                          //To use TLS
                          props.put("mail.smtp.auth", "true"); 
                          props.put("mail.smtp.starttls.enable", "true");
                          props.put("mail.smtp.password", "password");
                          //To use SSL
                          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 , null);
                          String to = "me@gmail.com";
                          String from = "from@gmail.com";
                          String subject = "Testing...";
                          Message msg = new MimeMessage(session);
                          try {
                              msg.setFrom(new InternetAddress(from));
                              msg.setRecipient(Message.RecipientType.TO, 
                                  new InternetAddress(to));
                              msg.setSubject(subject);
                              msg.setText("Working fine..!");
                              Transport transport = session.getTransport("smtp");
                              transport.connect("smtp.gmail.com" , 465 , "username", "password");
                              transport.send(msg);
                              System.out.println("fine!!");
                          }
                          catch(Exception exc) {
                              System.out.println(exc);
                          }
                      }
                  }
                  

                  即使在输入密码后,我也得到了异常.为什么不认证?

                  Even after giving the password I get the exception. Why is it not authenticating?

                  推荐答案

                  尝试创建一个 javax.mail.Authenticator 对象,并将其与 properties 对象一起发送到 Session 对象.

                  Try to create an javax.mail.Authenticator Object, and send that in with the properties object to the Session object.

                  身份验证器

                  您可以修改它以接受用户名和密码,并且可以将它们存储在那里或任何您想要的地方.

                  You can modify this to accept a username and password and you can store them there, or where ever you want.

                  public class SmtpAuthenticator extends Authenticator {
                  public SmtpAuthenticator() {
                  
                      super();
                  }
                  
                  @Override
                  public PasswordAuthentication getPasswordAuthentication() {
                   String username = "user";
                   String password = "password";
                      if ((username != null) && (username.length() > 0) && (password != null) 
                        && (password.length   () > 0)) {
                  
                          return new PasswordAuthentication(username, password);
                      }
                  
                      return null;
                  }
                  

                  在您发送电子邮件的班级中:

                  In your class where you send the email:

                  SmtpAuthenticator authentication = new SmtpAuthenticator();
                  javax.mail.Message msg = new MimeMessage(Session
                                      .getDefaultInstance(emailProperties, authenticator));
                  

                  这篇关于javax.mail.AuthenticationFailedException:连接失败,没有指定密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Compiling C++ for the JVM(为 JVM 编译 C++)
                  Compile to java bytecode (without using Java)(编译成java字节码(不使用Java))
                  How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?(如何在编译时驱动 C#、C++ 或 Java 编译器计算 1+2+3+...+1000?)
                  Java ClassLoader: load same class twice(Java ClassLoader:两次加载相同的类)
                  How to debug .class files in ECLIPSE?(如何在 ECLIPSE 中调试 .class 文件?)
                  Java quot;The blank final field may not have been initializedquot; Anonymous Interface vs Lambda Expression(Java“可能尚未初始化空白的最终字段匿名接口与 Lambda 表达式)

                  <legend id='e8rxU'><style id='e8rxU'><dir id='e8rxU'><q id='e8rxU'></q></dir></style></legend>
                  <tfoot id='e8rxU'></tfoot>
                    1. <small id='e8rxU'></small><noframes id='e8rxU'>

                        <bdo id='e8rxU'></bdo><ul id='e8rxU'></ul>
                        • <i id='e8rxU'><tr id='e8rxU'><dt id='e8rxU'><q id='e8rxU'><span id='e8rxU'><b id='e8rxU'><form id='e8rxU'><ins id='e8rxU'></ins><ul id='e8rxU'></ul><sub id='e8rxU'></sub></form><legend id='e8rxU'></legend><bdo id='e8rxU'><pre id='e8rxU'><center id='e8rxU'></center></pre></bdo></b><th id='e8rxU'></th></span></q></dt></tr></i><div id='e8rxU'><tfoot id='e8rxU'></tfoot><dl id='e8rxU'><fieldset id='e8rxU'></fieldset></dl></div>
                            <tbody id='e8rxU'></tbody>