发送邮件时附件名称乱码问题解决

yun-zuoyi
yanyujia 2 years ago
parent f94aca15b8
commit 346e3441d0

@ -218,7 +218,7 @@ public class MailUtil {
* @param attachmentByte
* @throws MessagingException
*/
public void addAttachment(String fileName, byte[] attachmentByte) throws MessagingException {
public void addAttachment(String fileName, byte[] attachmentByte) throws MessagingException, UnsupportedEncodingException {
addAttachment(fileName, attachmentByte,
FileContentTypeTool.getContentType(StringTool.getStringFileSuffix(fileName, true)));
}
@ -231,11 +231,12 @@ public class MailUtil {
* @param contentType
* @throws MessagingException
*/
public void addAttachment(String fileName, byte[] attachmentByte, String contentType) throws MessagingException {
public void addAttachment(String fileName, byte[] attachmentByte, String contentType) throws MessagingException, UnsupportedEncodingException {
BodyPart attachmentBodyPart = new MimeBodyPart();
DataSource source = new ByteArrayDataSource(attachmentByte, contentType);
attachmentBodyPart.setDataHandler(new DataHandler(source));
attachmentBodyPart.setFileName(fileName);
String name = MimeUtility.encodeText(fileName);
attachmentBodyPart.setFileName(name);
attachmentList.add(attachmentBodyPart);
}

Loading…
Cancel
Save