在我的应用程序中我用来发送带附件的邮件我写这样的代码
使用System.Net.Mail;
MailMessage mail = new MailMessage();
mail.Body = "<html><body><b> Name Of The Job Seeker: " + txtName.Text + "<br><br>" + "The Mail ID:" + txtEmail.Text + "<br><br>" + " The Mobile Number: " + txtmobile.Text + "<br><br>" + "Position For Applied: " + txtPostionAppl.Text + "<br><br>" + "Description " + txtdescript.Text + "<br><br></b></body></html>";
mail.From = new MailAddress ( txtEmail.Text);
mail.To .Add (new MailAddress ( mailid));
mail.Priority = MailPriority.High;
FileUpload1.PostedFile.SaveAs("~/Resume/" + FileUpload1.FileName);
mail.Attachments.Add(filenme);
SmtpMail sm = new SmtpMail();
sm.Send(mail);
它在附件上给出了错误,例如mail.Attachemts.Add(filena)
像这样'System.Collections.ObjectModel.Collection.Add(System.Net.Mail.Attachment)'有一些无效的参数。
答案 0 :(得分:1)
你的语法错了。有关正确的语法,请参阅此文章
http://www.systemnetmail.com/faq/2.3.aspx
您只能通过指定文件名来添加附件。您必须专门创建一个附件对象并添加它。 (如链接文章所示。)
像这样:mail.Attachments.Add(new Attachment(filename));