Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将Outlook.MailItem附件转换为inputstream?_C#_Amazon S3_Outlook Addin - Fatal编程技术网

C# 如何将Outlook.MailItem附件转换为inputstream?

C# 如何将Outlook.MailItem附件转换为inputstream?,c#,amazon-s3,outlook-addin,C#,Amazon S3,Outlook Addin,我想在outlook帐户中获取电子邮件时将附件保存到AWS bucket中。 我尝试使用HttpPostedFileBase,它具有InputStream属性 我试着像下面一样 //successfully saving 'HttpPostedFileBase' files using (IAmazonS3 s3client = new AmazonS3Client(_awsAccessKey, _awsSecretKey, RegionEndpoint.USEast1)) { Put

我想在outlook帐户中获取电子邮件时将附件保存到AWS bucket中。 我尝试使用
HttpPostedFileBase
,它具有
InputStream
属性

我试着像下面一样

//successfully saving 'HttpPostedFileBase' files

using (IAmazonS3 s3client = new AmazonS3Client(_awsAccessKey, _awsSecretKey, RegionEndpoint.USEast1)) {
    PutObjectRequest putObjectRequest = new PutObjectRequest {
        BucketName = _bucketName,
        CannedACL = S3CannedACL.PublicRead,
        Key = string.Format("uploads/" + AssignedTaskId.ToString() + "/" + Path.GetFileName(postedFile.FileName)),
        InputStream = postedFile.InputStream
    };
    s3client.PutObject(putObjectRequest);
}

//but cannot get from Outlook.MailItem attachments

Outlook.MailItem newEmail = null;
foreach (object collectionItem in inBoxItems) {
    newEmail = collectionItem as Outlook.MailItem;
}
using (IAmazonS3 s3client = new AmazonS3Client(_awsAccessKey, _awsSecretKey, RegionEndpoint.USEast1)) {
    PutObjectRequest putObjectRequest = new PutObjectRequest {
        BucketName = _bucketName,
        CannedACL = S3CannedACL.PublicRead,
        Key = string.Format("uploads/{0}", newEmail.Attachments[i].FileName),
        InputStream = newEmail.Attachments[i].InputStream
    };
    s3client.PutObject(putObjectRequest);
}
}
获取错误:

“Attachment”不包含“InputStream”的定义,并且找不到接受“Attachment”类型的第一个参数的可访问扩展方法“InputStream”(是否缺少using指令或程序集引用?)


Outlook对象模型没有为此提供任何属性。相反,您可以访问低级属性:

 const string PR_ATTACH_DATA_BIN = "http://schemas.microsoft.com/mapi/proptag/0x37010102";

 Outlook.Attachment attachment = mail.Attachments[0];  

 // Retrieve the attachment as a byte array
 var attachmentData = attachment.PropertyAccessor.GetProperty(PR_ATTACH_DATA_BIN);

另一个选项是将附件(请参见
附件.SaveAsFile
)保存到一个文件中,然后以字节流的形式打开该文件。

谢谢您的回答,但出现了一个错误:无法隐式将类型byte[]转换为'System.Io.stream'stream=new MemoryStream(byteArray);PropertyAccessor.GetProperty(PR_ATTACH_DATA_BIN)不适用于大型附件。