publicstaticStringsendHtmlEmail(String from,String[]to,String[] cc,String[] bcc,String subject,String content,List<File> fileList,String[] fileName){// Create the email message// 设置邮件信息ImageHtmlEmail email =newImageHtmlEmail();try{config(email,from,to,cc,bcc,subject);DataSourceResolver[] dataSourceResolvers =newDataSourceResolver[]{newDataSourceFileResolver()};
email.setDataSourceResolver(newDataSourceCompositeResolver(dataSourceResolvers));// set the html message
email.setHtmlMsg(content);// set the alternative message
email.setTextMsg("Your email client does not support HTML messages");if(fileList!=null){for(int i=0;i<fileList.size();i++){File file = fileList.get(i);EmailAttachment attachment =newEmailAttachment();
attachment.setPath(file.getPath());
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription(fileName[i]);
attachment.setName(fileName[i]);
email.attach(attachment);}}
email.send();}catch(EmailException e){
e.printStackTrace();return"false";}catch(Exception e){
e.printStackTrace();return"false";}finally{if(fileList!=null){for(int i=0;i<fileList.size();i++){
fileList.get(i).delete();}}}return"true";}