[英]Attachments.Add() missing multiple files
請檢查以下簡單的郵件方法。 出於測試目的,我已經通過文件位置路徑字符串手動附加了兩個文件,正如您可以在mail.Attachments.Add(new Attachment(@"C:\\Users...
但是這種方法的問題是當我運行它時第一個附件與電子郵件附件在一起,但第二個附件總是丟失。我在這里做錯什么了嗎?有任何想法嗎?預先感謝
public static bool SendEmail(string password, string from, string to, string cc, string subject, string[] attachedFiles, string body, string host, int port)
{
try
{
MailMessage mail = new MailMessage(from, to);
//foreach (var attachedFile in attachedFiles)
//{
// mail.Attachments.Add(new Attachment(attachedFile.ToString()));
//}
mail.Attachments.Add(new Attachment(@"C:\Users\liaka\Desktop\Jordan\FileMailer\FileMailer\Backlog_07_12_2018.xlsx"));
mail.Attachments.Add(new Attachment(@"C:\Users\liaka\Desktop\Jordan\FileMailer\FileMailer\test.txt"));
mail.Subject = subject;
mail.Body = body;
mail.CC.Add(cc);
var client = new SmtpClient(host, port)
{
Credentials = new NetworkCredential(from, password),
EnableSsl = true
};
client.Send(mail);
return true;
}
catch (Exception ex)
{
return false;
}
}
根據我的檢查,您的MailMessage()
方法的用法看起來不錯。 我已經測試了自己,並且可以很好地處理多個附件。 現在,您只能檢查哪些是-
1)您提供的文件路徑中確實存在您的文件。 (通過使用Windows文件資源管理器地址欄訪問該路徑進行檢查)
2)您嘗試附加的文件(特別是缺少的那個文件)不是空文件(因為當我運行測試空文件時沒有附加,但是使用gmail SMTP進行測試)
如果以上情況是正確的,那么我認為這可能與您的其他電子郵件設置有關?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.