|
|
@@ -8,6 +8,7 @@ import javax.activation.DataSource;
|
|
|
import javax.activation.FileDataSource;
|
|
|
import javax.mail.*;
|
|
|
import javax.mail.internet.*;
|
|
|
+import java.io.File;
|
|
|
import java.util.Properties;
|
|
|
|
|
|
/**
|
|
|
@@ -65,15 +66,14 @@ public class SendMailUtils {
|
|
|
MimeMultipart multipart = new MimeMultipart("mixed");
|
|
|
|
|
|
if(StringUtils.isNotEmpty(filename)){
|
|
|
- // 附件部分
|
|
|
- messageBodyPart = new MimeBodyPart();
|
|
|
- // 设置要发送附件的文件路径
|
|
|
- DataSource source = new FileDataSource(filename);
|
|
|
- messageBodyPart.setDataHandler(new DataHandler(source));
|
|
|
- // messageBodyPart.setFileName(filename);
|
|
|
- // 处理附件名称中文(附带文件路径)乱码问题
|
|
|
- messageBodyPart.setFileName(MimeUtility.encodeText(filename));
|
|
|
- multipart.addBodyPart(messageBodyPart);
|
|
|
+ File file = new File(filename);
|
|
|
+ if(file.exists()){
|
|
|
+ messageBodyPart = new MimeBodyPart();
|
|
|
+ DataSource source = new FileDataSource(filename);
|
|
|
+ messageBodyPart.setDataHandler(new DataHandler(source));
|
|
|
+ messageBodyPart.setFileName(MimeUtility.encodeText(file.getName(), "UTF-8", "B"));
|
|
|
+ multipart.addBodyPart(messageBodyPart);
|
|
|
+ }
|
|
|
}
|
|
|
//html代码部分
|
|
|
MimeBodyPart htmlPart = new MimeBodyPart();
|