Announcement Announcement Module
No announcement yet.
Content-transfer-Encoding is getting set to quoted-printable by default. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Content-transfer-Encoding is getting set to quoted-printable by default.


    I am using Spring 3.0.6 with JavaMail 1.4.

    I have requirement where I get Input request emaildata from Front End , once Get I store it in DB and meanwhile I construct and forward the email to required parties by Spring Java Mail API.

    Everything is working fine, I am able to store and forward email properly but one issue is coming while forwarding email with attachments.

    I am getting input data in JSON object from Front END like this.

    "sender":"[email protected]",
    "[email protected]"

    "message_id":"[email protected] ",
    "content_type":"text/plain; charset=us-ascii",
    "user_agent":"Mutt/1.5.20 (2009-06-14)",
    "message_body":"Test Message here!",
    "content_data":"R0lGODlheAAbAPcAAABNkwBNmABSlABVmw BYlwBYmgB3pgB4qgEAZQEAaQFDjgFXoAF2qgJYoAtingtioQ9= "

    'content_data' field in attachement is base64 encoded.

    Now while forwarding email I am using following code.

    protected void doSend(final EmailMessage mail) throws MailException
    sender.send(new MimeMessagePreparator()
    public void prepare(MimeMessage message) throws Exception
    MimeMessageHelper helper;

    List<ByteArrayAttachment> attachments = mail.getAttachables();

    if (mail.get_body() == null && mail.getAttachables() == null)
    // If the message has no body or attachments, create a
    // single-part message
    helper = new MimeMessageHelper(message, "UTF-8");
    } else
    // If the mail has attachments or it has a body (or both),
    // create a multipart message
    helper = new MimeMessageHelper(message, true, "UTF-8");

    if (mail.get_sender() != null)
    if (mail.getAddresses() != null && mail.getAddresses().length > 0)

    if (mail.get_subject() != null)

    String text = mail.get_body();
    String html = mail.get_htmlBody();
    if (text != null)
    if (html != null)
    helper.setText(text, html);
    } else
    } else if (html != null)
    helper.setText(html, true);

    if (!CollectionUtils.isEmpty(attachments))
    for (Attachment attachment : attachments)
    if (attachment.getContentType() == null)
    helper.addAttachment(attachment.getName(), new AttachmentInputStreamSource(attachment));
    helper.addAttachment(attachment.getName(), new AttachmentInputStreamSource(attachment),


    AttachmentInputStreamSource is simple class which extends InputStreamSource class and implements

    String contentData = "R0lGODlheAAbAPcAAABNkwBNmABSlABVmwBYlwBYmgB3pgB4q gEAZQEAaQFDjgFXoAF2qgJYoAtingtioQ9="; // Base64 encoded string coming from request.

    public InputStream getInputStream() throws IOException {
    if (attachment.hasStream()) {
    return attachment.getStream();
    return createStreamFromBytes(contentData.getBytes());

    protected InputStream createStreamFromBytes(byte[] bytes) throws IOException {
    return new ByteArrayInputStream(bytes);

    Everything looks perfect to me, but when I forward email , the Content-Transfer-Encoding of attachment section changes from
    'base64' to 'quoted-printable'

    Content-Type: image/png; name=ball_yellow.png
    Content-Transfer-Encoding: quoted-printable
    Content-Disposition: attachment; filename=ball_yellow.png

    I am totally stuck and not sure why Spring is modifying the Content-Transfer-Encoding field.

    And if yes, how should I set explicitly Content-Transfer-Encoding to base64 (Only for that attachment) on attachment level and not message level as I may get other attachment with other Content-Transfer-Encoding .

    I know to set the header of message like

    message.setHeader("Content-Transfer-Encoding", attachments.get(0).getContentTransferEncoding()); But it will set Header for whole message and not attachment only.

    Any help is very highly appreciated.


  • #2
    Any suggestion or help will be appreciated. I am stuck with this please!