0

I am using sendmail library of unix to send mail. I am sending a mail with an attachment which is a (Microsoft word) .docx file. This word file has images in it. The issue is, receiver is not able to open a mail attachment which is word (.docx file) with images inside it. Opening a Microsoft word file gives error "file is corrupted".

Receiver is able to open a word file if it has only text in it. Problem comes only when the word file has images in it, and that word file is being send as a attachment of a mail.

Here is the file content looks like. This is a sh file, and use sendmail api of linux to execute this sh file for sending mail..

echo -e MIME-Version: 1.0;
echo -e 'Content-Type: multipart/mixed; boundary="CONTENT_BOUNDARY"';
echo ;
echo -e --CONTENT_BOUNDARY;
echo -e 'Content-Type: text/html; charset=utf-8';
echo ;
echo -e "  ";
echo ;
echo -e --CONTENT_BOUNDARY;
echo -e 'Content-Type: text/plain; charset=utf-8';
echo ;
echo -e "Hello World!";
echo ;
echo -e --CONTENT_BOUNDARY;
echo -e 'Content-Type: text/html; charset=utf-8';
echo ;
echo -e "<b>Hello</b> <i>World</i>!";
echo ;
echo -e --CONTENT_BOUNDARY;
echo -e 'Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document; name=Editor-issue-6-30-2016.docx';
echo -e 'Content-Transfer-Encoding: base64';
echo ;
echo -e PK

When the attached word file is opened in the microsoft word, this is how it image looks like (not same as the original image)

This is how the image looks like doc file is opened in word

When I try to send the same attachment using other mail sending api like nodemailer in node.js, this attachment get properly opened by the receiver.

Any help highly appreciated.

Thanks.

Reena Upadhyay
  • 1,977
  • 20
  • 35

1 Answers1

0

From this: Using sendmail for HTML body and binary attachment

Try to change

'Content-Transfer-Encoding: base64';

to

'Content-Transfer-Encoding: uuencode';

and add

uuencode 'Editor-issue-6-30-2016.docx' $(basename 'Editor-issue-6-30-2016.docx')
farbiondriven
  • 2,450
  • 2
  • 15
  • 31
  • No it didn't work. I have added the image screenshot in question, When I open the mail attachment in word, the image is not displayed properly. – Reena Upadhyay Dec 05 '17 at 16:42