工具類(MailUtils)發郵件

所需jar包:

封裝好的itcast-tools-1.4.2.jarsession

所需依賴的jar包:

activation.jarspa

mail.jarcode

代碼示例:

    @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);
    }
相關文章
相關標籤/搜索