我通过file attachment
做memory 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...
您应该使用MediaTypeNames.Application.Octet作为MIME类型。
感谢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,以及.docx
和5000 words
一个qazxsw POI文件进行了测试,它被重建它在我的Gmail客户端的方式。
刚刚测试的是,它也可以与tables
以同样的方式,所以没有必要pictures
。