支持附件以链接的形式发送
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user