开发者

Error while sending mail (attachment file)

in my application i am using to send mail with attachments i write the code like this

Using 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);

it is giving error at attachment like mail.Attachemts.Add(filena)

like this

'Syst开发者_StackOverflowem.Collections.ObjectModel.Collection.Add(System.Net.Mail.Attachment)' has some invalid arguments.


Your syntax is wrong. See this article for the correct syntax,

http://www.systemnetmail.com/faq/2.3.aspx

You can't add an attachment simply by specifying the filename. You have to specifically create an attachment object and add that. (as shown in the linked article.)

like this:

mail.Attachments.Add(new Attachment(filename));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜