<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)

        时间:2023-10-14
      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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:无法连接到 SMTP 主机:smtp.gmail.com,端口:465,响应:-1 下一篇:如何有效地使用 javax.mail API 发送批量邮件?&amp;我们可以使用重用经过身份验证的会话来提高速

                  相关文章

                    <bdo id='OSXD8'></bdo><ul id='OSXD8'></ul>
                2. <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>

                  1. <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'>