在.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