-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Closed
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancementA general enhancement
Milestone
Description
When we use MimeMessageHelper to add inline images those appears as "noname" attachment in gmail client, but are inlined correctly.
Even if we define.
var originalFileName = Objects.requireNonNull(image.getOriginalFilename());
var contentType = FileTypeMap.getDefaultFileTypeMap().getContentType(originalFileName);
var byteArrayDataSource = new ByteArrayDataSource(image.getInputStream(), contentType);
byteArrayDataSource.setName(originalFileName);
mimeMessageHelper.addInline(originalFileName, byteArrayDataSource);
But it not is an elegant presentation for us.
To solve this we override MimeMessageHelper to add fileName on
"public void addInline(String contentId, DataSource dataSource) throws MessagingException"
public class InlineFileNameMimeMessageHelper extends MimeMessageHelper {
public InlineFileNameMimeMessageHelper(MimeMessage mimeMessage, boolean multipart) throws MessagingException {
super(mimeMessage, multipart);
}
public void addInline(String contentId, DataSource dataSource) throws MessagingException {
Assert.notNull(contentId, "Content ID must not be null");
Assert.notNull(dataSource, "DataSource must not be null");
var mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setDisposition(Part.INLINE);
mimeBodyPart.setContentID("<" + contentId + ">");
mimeBodyPart.setDataHandler(new DataHandler(dataSource));
// MimeMessageHelper do not adds filename
mimeBodyPart.setFileName(dataSource.getName());
getMimeMultipart().addBodyPart(mimeBodyPart);
}
}
And with this change we have te expected name on preview.
It is possible to add this or similiar behaviour on future releases?
Thank you.
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancementA general enhancement