java发送带有附件的电子邮件

java发送带有附件的电子邮件,java,Java,我建议使用ApacheCommons电子邮件,而不是直接使用JavaMail API。后者非常棘手,有很多边缘条件,需要对MIME有很好的理解 以下是您要求的示例: 我很幸运地使用了这个库,并根据第一手经验推荐了它 现在它是可读的,请解释它有什么问题 package abc; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import org.apa

我建议使用ApacheCommons电子邮件,而不是直接使用JavaMail API。后者非常棘手,有很多边缘条件,需要对MIME有很好的理解

以下是您要求的示例:


我很幸运地使用了这个库,并根据第一手经验推荐了它

现在它是可读的,请解释它有什么问题
package abc;

import java.io.FileInputStream;
import java.io.FileOutputStream;  
import java.io.IOException;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFBorderFormatting;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;

import java.util.Iterator;

public class read {
    public static void main(String[] args) throws IOException {

        String Filepath = "C:\\test.xls";
        FileInputStream input = new FileInputStream("Filepath");

        HSSFWorkbook wb = new HSSFWorkbook(); //Access the workbook
        //Access the worksheet, so that we can update / modify it.     
        HSSFSheet worksheet = wb.getSheetAt(0); 


        Cell cell = null; // declare a Cell object

        cell = worksheet.getRow(2).getCell(2);
        CellStyle style = wb.createCellStyle();
        style.setFillForegroundColor(IndexedColors.BLUE.getIndex());

        cell.setCellStyle(style);

        try {           
            FileOutputStream output = new FileOutputStream(
                "C:\\Users\\TEMP\\Desktop\\downloads.xls"
            );
            wb.write(output);
            output.close(); 
        } catch(Exception e){
            e.printStackTrace();
        }        
    }
}