我正在使用unix的sendmail库发送邮件。我正在发送一个附件的邮件,这是一个(Microsoft ) .docx文件。这个单词文件中有图像。问题是,接收方无法打开包含图像的邮件附件( word (.docx文件))。打开Microsoft文件会导致错误“文件已损坏”.
如果单词文件中只有文本,则接收方能够打开该文件。只有当word文件中有图像,并且该word文件作为邮件附件发送时,才会出现问题。
文件内容如下所示。这是一个sh文件,并使用linux的sendmail来执行这个sh文件来发送邮件。
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
当附加的word文件在microsoft中打开时,它的图像是(与原始图像不一样)
当我试图使用其他邮件发送api (如node.js中的nodemailer )发送相同的附件时,接收方会正确地打开该附件。
任何帮助都非常感谢。
谢谢。
发布于 2017-12-05 08:12:09
从这里:Using sendmail for HTML body and binary attachment
试着改变
'Content-Transfer-Encoding: base64';
至
'Content-Transfer-Encoding: uuencode';
再加上
uuencode 'Editor-issue-6-30-2016.docx' $(basename 'Editor-issue-6-30-2016.docx')
https://stackoverflow.com/questions/47657875
复制相似问题