小编Udh*_*ata的帖子

如何使用 Spring Boot 通过电子邮件发送文件而不先将其存储在存储中?

我正在开发一个 Spring Boot 应用程序。在我的项目中,我正在创建一个 .xlsx 文件,然后我必须使用 Spring Boot 通过电子邮件发送。

我可以使用 apache poi 创建该文件,但稍后通过邮件将其作为附件发送,我应该将该文件保存在本地的某个位置,然后将文件移回原处,同时将其作为附件发送。

有什么方法可以创建 .xlsx 文件并直接通过电子邮件发送它,而无需先将其保存在某处?

对于邮件,我使用'org.springframework.boot:spring-boot-starter-mail'

对于.xlsx,我使用“org.apache.poi”,名称:“poi”,版本:“4.1.2”“org.apache.poi”,名称:“poi-ooxml”,版本:“4.1.2” '

源代码

       XSSFWorkbook workbook = new XSSFWorkbook();
       List<String> s = Arrays.asList("person","animal");
       CellStyle style = workbook.createCellStyle();
       style.setWrapText(true);
       int n = 1;
       String source = s.get(0);
       Sheet sheet = workbook.createSheet(source);
       for (String i : s) {
           if(!source.equalsIgnoreCase(i)) {
               sheet = workbook.createSheet(i);
               Row header = sheet.createRow(0);

               CellStyle headerStyle = workbook.createCellStyle();

               XSSFFont font = workbook.createFont();
               font.setFontName("Arial");
               font.setBold(true);
               headerStyle.setFont(font);

               Cell headerCell = …
Run Code Online (Sandbox Code Playgroud)

java apache-poi spring-boot

3
推荐指数
1
解决办法
3668
查看次数

标签 统计

apache-poi ×1

java ×1

spring-boot ×1