发送邮件(@163.com)

1.添加依赖,

      commons-email  等等

@Test

    public void sendMail() throws EmailException, MalformedURLException, UnsupportedEncodingException {
        //可以添加发送响应的类

        HtmlEmail email = new HtmlEmail();

       //HostName的配置

        email.setHostName("smtp.163.com");

       //发送文件的邮箱地址

        email.setAuthenticator(new DefaultAuthenticator("ycdl_mail@163.com", "1qaz2wsx"));
        email.setSSLOnConnect(true);

      //接收文件的邮箱地址

        email.addTo("16910735@qq.com", "");

     //发送文件的邮箱及密码

        email.setFrom("ycdl_mail@163.com", "wq");
        email.setSubject("账号激活");

        email.setCharset("UTF-8");

        // embed the image and get the content id
        URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
        String cid = email.embed(url, "Apache logo");
        // set the html message
        String content="<html><meta charset=\"utf-8\" />" +
                "账号激活地址:<a href='http://localhost:8080/user/xxxxxxxxxxxx'>http://localhost:8080/user/xxxxxxxxxxxx</a>"+
                "</html>";
        email.setHtmlMsg(new String(content.getBytes(),"UTF-8"));
        // set the alternative message;文件的内容
        email.setTextMsg("此邮件不需要回复");

        // send the email;确认发送

        email.send();

    }

版权声明:本文为jeffhymm原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。