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

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

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

        JavaMail smtp 属性(用于 STARTTLS)

        JavaMail smtp properties (for STARTTLS)(JavaMail smtp 属性(用于 STARTTLS))
      1. <legend id='znW0F'><style id='znW0F'><dir id='znW0F'><q id='znW0F'></q></dir></style></legend>

          <tbody id='znW0F'></tbody>

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

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

                1. 本文介绍了JavaMail smtp 属性(用于 STARTTLS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  JavaMail 指定了一组可以设置为配置 SMTP 连接的属性.要使用 STARTTLS,需要设置以下属性

                  JavaMail specifies a bunch of properties that can be set to configure an SMTP connection. To use STARTTLS it is necessary to set the following property

                  mail.smtp.starttls.enable=true
                  

                  在哪里指定用户名/密码以使用 smtp 服务?是否足以指定:

                  Where do I specify the username/password to use the smtp service? Is it enough to specify the:

                  mail.smtp.user=me
                  mail.smtp.password=secret
                  

                  或者我必须使用以下方式显式登录:

                  Or do I have to explicitely login using the:

                  transport.connect(server, userName, password)
                  

                  是的,我已经尝试过这样做,似乎有必要使用 transport.connect(..) 进行连接.但如果是,mail.smtp.user &传递属性?他们还不足以将 smtp 与 starttls 一起使用吗?

                  Yes, I already tried to do this and it seems that it is necessary to connect using transport.connect(..). But if yes, what are the mail.smtp.user & pass properties for? Are they not enough to use smtp with starttls?

                  推荐答案

                  这是我的 sendEmail 方法,它使用 GMail smtp (JavaMail) 和 STARTTLS

                  Here is my sendEmail method which is using GMail smtp (JavaMail) with STARTTLS

                  public void sendEmail(String body, String subject, String recipient) throws MessagingException,
                              UnsupportedEncodingException {
                          Properties mailProps = new Properties();
                          mailProps.put("mail.smtp.from", from);
                          mailProps.put("mail.smtp.host", smtpHost);
                          mailProps.put("mail.smtp.port", port);
                          mailProps.put("mail.smtp.auth", true);
                          mailProps.put("mail.smtp.socketFactory.port", port);
                          mailProps.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
                          mailProps.put("mail.smtp.socketFactory.fallback", "false");
                          mailProps.put("mail.smtp.starttls.enable", "true");
                  
                          Session mailSession = Session.getDefaultInstance(mailProps, new Authenticator() {
                  
                              @Override
                              protected PasswordAuthentication getPasswordAuthentication() {
                                  return new PasswordAuthentication(login, password);
                              }
                  
                          });
                  
                          MimeMessage message = new MimeMessage(mailSession);
                          message.setFrom(new InternetAddress(from));
                          String[] emails = { recipient };
                          InternetAddress dests[] = new InternetAddress[emails.length];
                          for (int i = 0; i < emails.length; i++) {
                              dests[i] = new InternetAddress(emails[i].trim().toLowerCase());
                          }
                          message.setRecipients(Message.RecipientType.TO, dests);
                          message.setSubject(subject, "UTF-8");
                          Multipart mp = new MimeMultipart();
                          MimeBodyPart mbp = new MimeBodyPart();
                          mbp.setContent(body, "text/html;charset=utf-8");
                          mp.addBodyPart(mbp);
                          message.setContent(mp);
                          message.setSentDate(new java.util.Date());
                  
                          Transport.send(message);
                      }
                  

                  这篇关于JavaMail smtp 属性(用于 STARTTLS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 表达式)
                    <bdo id='OSXD8'></bdo><ul id='OSXD8'></ul>
                    <i id='OSXD8'><tr id='OSXD8'><dt id='OSXD8'><q id='OSXD8'><span id='OSXD8'><b id='OSXD8'><form id='OSXD8'><ins id='OSXD8'></ins><ul id='OSXD8'></ul><sub id='OSXD8'></sub></form><legend id='OSXD8'></legend><bdo id='OSXD8'><pre id='OSXD8'><center id='OSXD8'></center></pre></bdo></b><th id='OSXD8'></th></span></q></dt></tr></i><div id='OSXD8'><tfoot id='OSXD8'></tfoot><dl id='OSXD8'><fieldset id='OSXD8'></fieldset></dl></div>
                        <tbody id='OSXD8'></tbody>

                      • <tfoot id='OSXD8'></tfoot>
                          <legend id='OSXD8'><style id='OSXD8'><dir id='OSXD8'><q id='OSXD8'></q></dir></style></legend>

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