如何.DOCX和.doc文件附加到从内存流的电子邮件?

问题描述 投票:0回答:2

我通过file attachmentmemory stream因为temporary storage是不是一种选择。

在这里,我做了一个Jpeg图像附件。我看着与您可以通过切换MediaTypeNames做同样的,可惜.doc.docx是不在其中的其他文件类型。

我想知道任何你是否知道任何package and how to use it对于这个特定的场合?

//...set up MailMessage, add a bunch of non-file content to it

MemoryStream jpgStream = new MemoryStream();
string filename = uploadedFile.FileName;

System.Drawing.Image theImage = System.Drawing.Image.FromStream(uploadedFile.InputStream);

theImage.Save(jpgStream, System.Drawing.Imaging.ImageFormat.Jpeg); 

jpgStream.Seek(0L, SeekOrigin.Begin);
emailMessage.Attachments.Add(new Attachment(jpgStream, filename, System.Net.Mime.MediaTypeNames.Image.Jpeg));

//something extra and send email...
c# .net asp.net-mvc memorystream .doc
2个回答
0
投票

您应该使用MediaTypeNames.Application.Octet作为MIME类型。

来源:https://docs.microsoft.com/fr-fr/dotnet/api/system.net.mime.mediatypenames.application.octet?view=netframework-4.7.2


0
投票

感谢Benoit Gidon他的回答。我再次强调,你的假设是你最大的敌人证明。

显然,它是如此简单,当你把file.InputStream直接进入连接,不像其他S.O.你不需要任何其它特殊的方法,只要帖子让你相信:https://stackoverflow.com/questions/9095880/attach-multiple-image-formats-not-just-jpg-to-email

https://stackoverflow.com/questions/5336239/attach-a-file-from-memorystream-to-a-mailmessage-in-c-sharp

在任何情况下,实际上是与它挣扎着,这里是代码:

foreach (HttpPostedFileBase file in fullViewModel.filesCollection)
            {
                string filename = file.FileName;

                 msg.Attachments.Add(new Attachment(file.InputStream, filename, MediaTypeNames.Application.Octet));
            }

我有在它里面的内容qazxsw POI,以及.docx5000 words一个qazxsw POI文件进行了测试,它被重建它在我的Gmail客户端的方式。

刚刚测试的是,它也可以与tables以同样的方式,所以没有必要pictures

© www.soinside.com 2019 - 2024. All rights reserved.