請檢查下面的簡單郵件方法。出于測試目的,我通過文件位置路徑字符串手動附加了兩個文件,如您所見 -mail.Attachments.Add(new Attachment(@"C:\Users... 但是這種方法的問題是,當(dāng)我運行它時,第一個附件與電子郵件一起附加,但總是缺少第二個附件。我在這里做錯了什么?任何想法?提前致謝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; } }
Attachments.Add() 缺少多個文件
ibeautiful
2022-06-12 10:32:03