工具类(MailUtils)发邮件

所需jar包:

封装好的itcast-tools-1.4.2.jar

所需依赖的jar包:

activation.jar

mail.jar

代码示例:

    @Test
    public void fun3() throws MessagingException, IOException{
        /*
         * 1.得到Session
         */
        Session session = MailUtils.createSession("smtp.163.com", "13271315317", "xjs19980715");
        //2.创建邮件对象
        Mail mail=new Mail("13271315317@163.com","1874704478@qq.com","标题:谢军帅是晓峰哥哥","正文:对");//发件人,收件人
        //附件对象
        AttachBean ab1=new AttachBean(new File("G:/金泰妍.jpg"), "金泰妍.jpg");
        AttachBean ab2=new AttachBean(new File("G:/金泰妍.mp3"), "金泰妍.mp3");
        //把附件加到邮件中
        mail.addAttach(ab1);
        mail.addAttach(ab2);
        //3.发送
        MailUtils.send(session, mail);
    }

 

posted @ 2019-06-10 15:36  微微亮  阅读(247)  评论(0编辑  收藏  举报