problem with adding attachment to a mail

B

Bart Stes

Hey guys,

I'm try to write a very simple winform app that allows the users to send an
email. I use the System.Web.Mail MailMessage class for this.
But when it comes to adding an attachment, something appears to go wrong.
After I execute the following code, the MailMessage appears to have an
attachment (looked it up through a watch in debug mode), but when I actually
send the message, the attachment is not send along with it. So the message
arrives in my inbox, but without the attachment. What am I doing wrong,

Many thanks,

Bart

public void AddAttachment (string file)

{

MailAttachment bijlage = new MailAttachment(file,MailEncoding.Base64);

if (!message.Attachments.Contains(bijlage))

{

message.Attachments.Add(bijlage);

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top