Stream as an Attachment to System.Net.Mail is 0 bytes

人走茶凉 提交于 2019-12-02 21:50:43

A guess... Back dat stream up to the beginning before sending nit

// Set the position to the beginning of the stream.
stream.Seek(0, SeekOrigin.Begin);
mail.Attachments.Add(new Attachment(stream, "myPdf.pdf"));
mail.Send();

Have you tried saving the file and then attaching the file, rather than attempting to attach a stream?

added

The normal process here would be

  1. Use the stream to create a file on disk

  2. Attach the file to an email

  3. Delete the file when done with it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!