[英]Attach ZIP-File to an email, without Filesystem
我正在尝试压缩 XML 文件,然后将它们附加到电子邮件中。
在此过程中,XML 文件和 zip 文件都不应该在文件系统上,只能在内存中。 ZIP 文件应仅存在于电子邮件的附件中。
我已经搜索了解决方案,但我很难理解它,因为我在编程方面比较新。 我什至不确定,如果可能的话。
这些是我目前使用的步骤:
//Creating the XML-Files
XDocument xmlFileOne = new XDocument();
XDocument xmlFileTwo = new XDocument();
xmlFileOne = new XDocument(
new XElement("Info",
new XElement("Test-Nr.", "1")));
xmlFileTwo = new XDocument(
new XElement("Info",
new XElement("Test-Nr.", "2")));
xmlFileOne.Save(@"C:\Users\Marc\Test\xmlFileOne.xml");
xmlFileTwo.Save(@"C:\Users\Marc\Test\xmlFileTwo.xml");
//Zipping the XML-Files and saving the Zip-File
using (Ionic.Zip.ZipFile zipFile = new ZipFile())
{
string fileName = @"C:\Users\TestUser\Test\zippedXML.zip";
//zipFile.Password = password;
zipFile.AddDirectory(@"C:\Users\TestUser\Test\");
zipFile.Save(fileName);
}
//Adding the Zip-File as Attachment on the Email
//Email works with MAPI
SendEmail sendEmail = new SendEmail();
sendEmail.AddRecipientTo("test123@gmail.com");
sendEmail.AddAttachment(@"C:\Users\TestUser\Test\zippedXML.zip");
sendEmail.SendMailPopup("Subject of Email", "Body of Email");
使用 Simple MAPI(您当前的实现)无法做到这一点。
相反,您可以考虑使用扩展 MAPI,它允许处理附件的二进制表示并在运行时动态设置它。 您对PR_ATTACH_DATA_BIN属性感兴趣,该属性包含通常通过对象链接和嵌入 (OLE) IStream
接口访问的二进制附件数据。 请注意,如果您不想处理低级代码,您可以考虑使用第三方组件(此 API 的包装器),例如 Redemption。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.