支持附件以链接的形式发送

This commit is contained in:
2025-07-16 16:05:08 +08:00
parent 2b92610ba4
commit 2ca2993613
2 changed files with 110 additions and 62 deletions

View File

@@ -355,4 +355,22 @@ public class EmailUtil {
return processedHtml;
}
/**
* 下载网络文件到本地临时文件
* @param url 文件的http/https链接
* @return 本地临时文件
*/
public static File downloadUrlToTempFile(String url) throws Exception {
File tempFile = File.createTempFile("mail_attach_", null);
try (java.io.InputStream in = new java.net.URL(url).openStream();
java.io.OutputStream out = new java.io.FileOutputStream(tempFile)) {
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
}
return tempFile;
}
}