我正在使用perl来组装一个multipart-MIME电子邮件,然后我在Windows环境中使用sendmail发送它。 我知道,不理想。
部分原因是收集文件,压缩文件,然后将zip文件编码为Base64,并将其作为附件写入电子邮件。 我的问题是,每当我发送超过一定大小的文件(我不确切知道大小是多少;介于20 KB和2 MB之间)时,zip文件最终会在收到时损坏。 (当在WinRAR中打开时,它会抱怨“意外结束归档”,并且CRC值都是零值,如果这是任何线索)。
我怀疑我可能只是将它写入电子邮件中,这样我就让垃圾或复制进入,但我无法看到它发生在哪里。 这是我用来进行阅读/编码/写作的片段; 它使用MIME :: Base64,显然有一个打开的Sendmail句柄。
open(FILE, "c:\\temp\\$uid.zip") or die "$!"; while (read(FILE, $buffer, 60*57)) { printf SENDMAIL encode_base64($buffer); }即使我在没有任何缓冲的情况下阅读它(我当然应该有足够的内存用于一个微不足道的2mb文件),我仍然收到一个损坏的zip文件。 大小肯定是混淆因素,但我正在努力弄清楚为什么或如何补救它。
I'm using perl to assemble a multipart-MIME email, which I'm then sending using sendmail, on a Windows environment. Not ideal, I know.
Part of this is collecting files, zipping them up, then encoding the zip file as Base64 and writing it into the email as an attachment. My problem is that whenever I send files over a certain size (I don't know exactly what size that is; somewhere between 20 KB and 2 MB) the zip file ends up corrupted on receipt. (When opened in WinRAR it complains "unexpected end of archive", and the CRC values are all zero-valued, if that's any clue).
I suspect I might just be writing it into the email in such a way that I'm letting garbage or duplication in, but I can't see where it's happening. Here's the snippet I'm using to do the reading/encoding/writing; it's using MIME::Base64, and obviously has an open Sendmail handle.
open(FILE, "c:\\temp\\$uid.zip") or die "$!"; while (read(FILE, $buffer, 60*57)) { printf SENDMAIL encode_base64($buffer); }Even when I read it in without any kind of buffering (I should certainly have enough memory for a paltry 2mb file), I still end up receiving a corrupted zip file. Size is definitely the confounding factor, but I'm struggling to figure out why or how to remedy it.
最满意答案
我认为在Windows上你需要binmode你的文件
open(FILE, "c:\\temp\\$uid.zip") or die "$!"; binmode FILE; while (read(FILE, $buffer, 60*57)) { printf SENDMAIL encode_base64($buffer); }另外,使用MIME :: Lite发送电子邮件。
I think on Windows you need to binmode your file
open(FILE, "c:\\temp\\$uid.zip") or die "$!"; binmode FILE; while (read(FILE, $buffer, 60*57)) { printf SENDMAIL encode_base64($buffer); }Also, use MIME::Lite for sending emails.
更多推荐
发布评论