zoukankan      html  css  js  c++  java
  • Java 向邮箱发送信息

    public class MailKit {
       public static void sendMail(String mailTo, String title, String code) {

          //发送者的邮箱
          String  from  = Static.MAIL_FROM;
          Properties props = System.getProperties();

          //邮箱格式qq/163
          props.setProperty("mail.smtp.host", "smtp.163.com");
          props.setProperty("mail.smtp.auth", "true");
          Session     session = Session.getInstance(props);
          MimeMessage message = new MimeMessage(session);
          try {
             message.setFrom(new InternetAddress(from));
             message.addRecipient(MimeMessage.RecipientType.TO, new InternetAddress(mailTo));
             message.setSubject(title);

             //短信内容
             message.setContent("<h1>此邮件为官方激活邮件!请点击下面链接完成激活操作!" + code + "</h1>", "text/html;charset=UTF-8");
             Transport transport = session.getTransport("smtp");

             //发送人的邮箱类型、用户名、密码
             transport.connect(Static.MAIL_HOST, Static.MAIL_USER, Static.MAIL_PASSWORD);
             transport.sendMessage(message, message.getAllRecipients());
          } catch (MessagingException e) {
             e.printStackTrace();
          }
       }

    }
    ————————————————
    版权声明:本文为CSDN博主「xinyugogo」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/weixin_38284251/article/details/81099679

  • 相关阅读:
    Centos7下安装oracle 11g,弹窗不显示或者显示太小
    SQLserver登陆报错
    centos7配置网易yum源
    python ----django---打包重用
    python打包exe文件
    Acwing-198-反素数(约数, 数学)
    Acwing-197-阶乘分解(质数)
    Acwing-196-质数距离(素数区间筛法)
    Acwing-169-数独2(搜索, 剪枝)
    Acwing-168-生日蛋糕(搜索, 剪枝)
  • 原文地址:https://www.cnblogs.com/BKhp/p/12090272.html
Copyright © 2011-2022 走看看