You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用sendmail发送Zip文件时首个文件损坏的问题求助

Fixing Corrupted First File in Zip Attachment Sent via Sendmail

Hey, I can spot exactly what's causing your first file in test.zip to be unreadable—your MIME email headers have a few critical typos and formatting gaps that are messing up how mail clients parse the attachment. Let’s break down the issues and fix them:

Key Problems in Your Original Command

  • Misspelled header: You wrote attachement instead of the correct attachment in the Content-Disposition line. This throws off how clients recognize and unpack the zip file, leading to corruption of the first entry.
  • Missing blank lines: MIME requires blank lines to separate email headers from content, and attachment headers from the actual encoded data. Without these, parts of your header get mixed into the zip's base64 content, breaking the file structure.
  • Incomplete boundary closure: The final boundary marker needs to end with -- (--X12345--) to signal the end of the multipart content. Your original command uses --X12345, which leaves the content unclosed in some clients.

Corrected Sendmail Command

( echo "From: from@from.com"
echo "To: to@to.com"
echo "Subject: subject"
echo "Mime-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="X12345"'
echo  # Blank line to separate main headers from multipart content
echo '--X12345'
echo "Content-Type: application/zip;"
echo "Content-Transfer-Encoding: base64"
echo "Content-Disposition: attachment; filename=test.zip"
echo  # Blank line to separate attachment headers from base64 data
base64 test.zip
echo  # Blank line to ensure boundary doesn't merge with zip content
echo '--X12345--'  # Properly close the multipart boundary
) | sendmail -t

What Each Fix Does

  1. Spelling correction: attachment tells the mail client this is an attached file, so it can properly handle the zip content without misinterpreting metadata.
  2. Blank lines: These are mandatory in MIME formatting—they act as clear separators so the client doesn't confuse header text with the actual binary data of your zip.
  3. Proper boundary closure: --X12345-- lets the client know there are no more parts to the email, preventing it from truncating or misreading the end of the zip file.

Give this corrected command a try—your test.zip should now be fully intact, with all three HTML files opening without errors.

内容的提问来源于stack exchange,提问作者Deepankumar R

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:56:49