CDO 消息:文本附件已损坏

发布于 2024-07-10 07:45:39 字数 1220 浏览 4 评论 0原文

我正在使用 CDO 对象(和 VB6,但这并不重要)创建电子邮件。

With New CDO.Message
  .To = "<address>"
  .Subject = "Manifest test 8"
  .Organization = "<company>"
  .From = "<address>"
  .Sender = .From

  With .Configuration
    .Fields(cdoSendUsingMethod).Value = cdoSendUsingPort
    .Fields(cdoSMTPServer).Value = "192.168.0.4"
    .Fields.Update
  End With

  With .AddAttachment("c:\import\customermanifestOURACCOUNT11122008110032.dat")
    .Fields(cdoContentDisposition).Value = "attachment; filename=""Consignor.dat"""
    .Fields.Update
  End With

  .Send
End With

如您所见,该邮件是空的,并包含我在电子邮件中重命名的附件。

附件是一个固定宽度的 ASCII 文本文件,其中包含我们系统的一些输出,每行一条记录,以 CRLF 分隔。

发送消息时,所有 CR 都会被删除,因此接收者收到的文件只有 LF,因此已损坏。

我尝试将 ContentEncoding 更改为 7 位和base64,不起作用。

我尝试将附件设置为 ContentMediaTypetext/plain,但没有成功。

我尝试添加后不重命名附件,但没有成功。

默认情况下,附件的 ContentMediaType 设置为 application/octet-stream,因此我无法弄清楚为什么(以及由什么)它首先被更改。

如果我在 .Send() 之后对附件执行 .SaveToFile(),它将在磁盘上保存有效文件。

这是我的代码的问题,还是邮件服务器设置的问题?

I'm creating an email message using CDO object (and VB6, but that doesn't really matter).

With New CDO.Message
  .To = "<address>"
  .Subject = "Manifest test 8"
  .Organization = "<company>"
  .From = "<address>"
  .Sender = .From

  With .Configuration
    .Fields(cdoSendUsingMethod).Value = cdoSendUsingPort
    .Fields(cdoSMTPServer).Value = "192.168.0.4"
    .Fields.Update
  End With

  With .AddAttachment("c:\import\customermanifestOURACCOUNT11122008110032.dat")
    .Fields(cdoContentDisposition).Value = "attachment; filename=""Consignor.dat"""
    .Fields.Update
  End With

  .Send
End With

As you can see, the message is empty and contains an attachment that I rename in the email.

The attachment is an ASCII text file, fixed-width, that contains some output from our systems, one record per line, separated with CRLF.

When the message gets sent, all CRs get stripped out the attachment, so the receiver gets a file that only has LFs and therefore is corrupted.

I tried to change ContentEncoding to 7bit and base64, didn't work.

I tried to set ContentMediaType for the attachment to text/plain, didn't work.

I tried to not rename the attachment after adding, didn't work.

The ContentMediaType for the attachment is set to application/octet-stream by default, so I can't figure out why (and by what) it gets changed in the first place.

If I execute .SaveToFile() on the attachment right after .Send(), it saves valid file on the disk.

Is this a problem in my code, or is it a mail server setting or something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉世弥音 2024-07-17 07:45:39

好吧,这很奇怪。

我们使用 Gmail 帐户来测试这个东西,更具体地说,是 Gmail Web 界面。 我们单击附件链接来保存收到的文件。 并且文件已损坏。

一旦我们尝试了一些厚客户端,结果就很好。 所有文件都可以正确下载,没有任何损坏。

所以我认为这是 gmail Web 界面(而不是 gmail POP3 界面)中的错误。

Ok, that was weird.

We used our gmail accounts to test that thing, more specifically, gmail web interface. We clicked attachments links to save reveived files. And the files were corrupted.

As soon as we instead tried some thick clients, it turned out to be fine. All files get download properly without any corruptions.

So I assume this is a bug in gmail web interface (as opposed to gmail POP3 interface).

葬﹪忆之殇 2024-07-17 07:45:39

我已经很长时间没有使用 CDO 了,但我记得过去也遇到过这个问题。 通过尝试不同的方法,我们发现如果邮件正文中有任何内容,则附件就会正确发送。

很奇怪,我知道。

尝试一下并告诉我们。

I have not used CDO in a long time, but i remember having this issue in the past. By trying different things, we figured that if there was any content in the body of the message the attachments were sent properly.

Weird, i know.

try it and let us know.

半世晨晓 2024-07-17 07:45:39

我刚刚遇到了同样的麻烦。 我切换到 Jmail,我的 CSV(文本文件)现在与我从 gmail 读取时的原始文件一模一样。

我比较了原始邮件(在 Gmail 中,选项 - 查看原始邮件),发现使用 CDO.Message,附件编码得不太好,它以文本格式保存,邮件客户端可以用它做他想做的事。 使用 Jmail,消息以 Base64 编码,因此从头到尾都保持其原始状态。 因此,在使用带有文本文件附件的 CDO.Message 时要小心! 尝试使用 Jmail(免费)代替。

CDO.message:内容传输编码:引用打印

Jmail.message:内容传输编码:base64

I just got this same trouble. I switched to Jmail and my CSV (text file) was now exactly like the original when I read it from gmail.

I compared the original message (in Gmail, option - view original message) and discovered that with CDO.Message, the attachment is not encoded really well, it is kept in text format, and the mail client do what he wants with it. With Jmail, the message is encoded in Base64 so it is kept in its original state from the start to the end. So, be careful when using CDO.Message with text file attachments! Try using Jmail (free) instead.

CDO.message: Content-Transfer-Encoding: quoted-printable

Jmail.message: Content-Transfer-Encoding: base64

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文