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

后端 未结 2 1089
温柔的废话
温柔的废话 2021-02-02 13:54

I\'ve got a project where I\'m using a PDF generator to send a file to a user. We\'d like to give the user the option to attach this file to an email instead, and we\'re having

相关标签:
2条回答
  • 2021-02-02 14:56

    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();
    
    0 讨论(0)
  • 2021-02-02 14:56

    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.

    0 讨论(0)
提交回复
热议问题