spring-email/src/main/java/com/xiongyingqi/email/service/impl/EmailService.java
private void handlerAttachments(EmailVo emailVo, MimeMessageHelper msgHelper) throws MessagingException {
        if (emailVo.getAttachmentVos() != null) {// 检查附件
            for (AttachmentVo attachmentVo : emailVo.getAttachmentVos()) {
                File attachment = attachmentVo.getAttachment();


                if (attachment == null) {
                    InputStream inputStream = attachmentVo.getAttachmentInputStream();

                    if (attachmentVo.getAttachmentName() == null) {
                        attachmentVo.setAttachmentName(new Date().toString());
                    }
                    InputStreamSource inputStreamSource = new InputStreamResource(inputStream);
                    msgHelper.addAttachment(attachmentVo.getAttachmentName(), inputStreamSource);
                } else {
                    if (attachmentVo.getAttachmentName() == null) {
                        attachmentVo.setAttachmentName(attachment.getName());
                    }

                    try {
                        msgHelper.addAttachment(MimeUtility.encodeWord(attachmentVo.getAttachmentName()), attachment);
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
private void handlerAttachments(EmailVo emailVo, MimeMessageHelper msgHelper) throws MessagingException {
        if (emailVo.getAttachmentVos() != null) {// 检查附件
            for (AttachmentVo attachmentVo : emailVo.getAttachmentVos()) {
                File attachment = attachmentVo.getAttachment();


                if (attachment == null) {
                    InputStream inputStream = attachmentVo.getAttachmentInputStream();

                    if (attachmentVo.getAttachmentName() == null) {
                        attachmentVo.setAttachmentName(new Date().toString());
                    }
                    InputStreamSource inputStreamSource = new InputStreamResource(inputStream);
                    msgHelper.addAttachment(attachmentVo.getAttachmentName(), inputStreamSource);
                } else {
                    if (attachmentVo.getAttachmentName() == null) {
                        attachmentVo.setAttachmentName(attachment.getName());
                    }

                    try {
                        msgHelper.addAttachment(MimeUtility.encodeWord(attachmentVo.getAttachmentName()), attachment);
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
处理附件

@param emailVo
@param msgHelper
@throws javax.mail.MessagingException