请检查下面的简单邮件方法。出于测试目的,我通过文件位置路径字符串手动附加了两个文件,如您所见 -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;
}
}
茅侃侃
相关分类