zoukankan      html  css  js  c++  java
  • 发送账号至邮箱激活方式

     //发送邮件  Mail接收收件人邮箱  url接受激活地址
        public static void sendMail(String Mail,String url)throws MessagingException {
            // 创建Properties 类用于记录邮箱的一些属性
            Properties props = new Properties();
            // 表示SMTP发送邮件,必须进行身份验证
            props.put("mail.smtp.auth", "true");
            //此处填写SMTP服务器
            props.put("mail.smtp.host", "smtp.qq.com");
            //端口号,QQ邮箱端口号
            props.put("mail.smtp.port", "587");
            // 此处填写你的账号
            props.put("mail.user", "279304739@qq.com");
            // 此处的密码就是前面说的16位STMP口令
            props.put("mail.password", "uuhtlxmkwscabifi");
    
            // 构建授权信息,用于进行SMTP进行身份验证
            Authenticator authenticator = new Authenticator() {
    
                protected PasswordAuthentication getPasswordAuthentication() {
                    // 用户名、密码
                    String userName = props.getProperty("mail.user");
                    String password = props.getProperty("mail.password");
                    return new PasswordAuthentication(userName, password);
                }
            };
            // 使用环境属性和授权信息,创建邮件会话
            Session mailSession = Session.getInstance(props, authenticator);
            // 创建邮件消息
            MimeMessage message = new MimeMessage(mailSession);
            // 设置发件人
            InternetAddress form = new InternetAddress(props.getProperty("mail.user"));
            message.setFrom(form);
            // 设置收件人的邮箱
            InternetAddress to = new InternetAddress(Mail);
            message.setRecipient(Message.RecipientType.TO, to);
            // 设置邮件标题
            message.setSubject("请点击以下链接激活您的邮箱");
            // 设置邮件的内容体
            message.setContent("<html lang='zh-CN'><head ><meta charset='utf-8'>"
                            + "</head><body>您好,欢迎订阅Victoria,请点击以下链接确认激活您的邮箱!<br><br>"
                            + "<a href="+url+">"+url+"</a></body></html>",
                    "text/html;charset=utf-8");
            // 发送邮件
            Transport.send(message);
        }
  • 相关阅读:
    vs2010使用刚刚配置好的STLport提示检测到"_MSC_VER”的不
    UltraISO制作Linux启动盘
    RedHat 简易配置 VNC Server 与VNC View详细说明!
    数据库中树状关系(各种树状分类)的查找
    java–jsp & javabean
    linux 下android的一键root
    MySQL简明教程及表设计原则
    Activity 生存周期
    java web EL表达式
    ubuntu下调试android手机,并进入手机shell终端
  • 原文地址:https://www.cnblogs.com/hechenhao/p/8136033.html
Copyright © 2011-2022 走看看