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