在.NET CORE
使用MailKit
一个附件可以使用加载:附加从.ZIP文件夹中的文件
bodyBuilder.Attachments.Add(FILE);
我试图使用从ZIP文件中附加文件:
using System.IO.Compression;
string zipPath = @"./html-files.ZIP";
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
// bodyBuilder.Attachments.Add("msg.html");
bodyBuilder.Attachments.Add(archive.GetEntry("msg.html"));
}
但它不起作用,并给我APP\"msg.html" not found
,这意味着它正试图从root
目录而不是zipped
目录加载一个具有相同名称的文件。
我现在建议的唯一的事情就是试着仔细地通过程序的声明来调试,看看变量的值。例如,你应该在VS的监视窗口中添加'archive'变量并调查它的属性 - 尤其是'Entries'。 – Deilan