[英]Adding multiple files to attachments using WebClient
我正在嘗試從我的網站儀表板發送包含多個附件的電子郵件。 但是,我的代碼只能附加最后一個文件。 我正在使用**WebClient()**
從Cloud系統下載文件,然后將它們添加為附件。
這是我編寫的代碼:
foreach (var link in attachments)
{
var uri = new Uri(link);
var s = uri.Segments[1];
var tempDirectory = @"c:\tempFolder\" + @"\"+ s;
WebClient webClient = new WebClient();
webClient.DownloadFile(link, tempDirectory);
Attachment attachment = new Attachment(tempDirectory);
attachment.ContentDisposition.Inline = true;
attachment.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
attachment.ContentId = model.Id.ToString();
attachment.ContentType.Name = s;
email.Attachments.Add(attachment);
}
任何幫助,將不勝感激
編輯:我附加了兩個文件,因此在每個循環中獲取這些鏈接:
循環1:abc.com/TestEmail1.txt
循環2:abc.com/TestEmail2.txt
刪除這些行解決了我的問題
attachment.ContentDisposition.Inline = true;
attachment.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
attachment.ContentId = model.Id.ToString();
attachment.ContentType.Name = s;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.