problem with Mail attachments

B

Bart Stes

Hey Guys,

I'm trying to write a very simple thing that allows a user to send an e-mail
from a windows form app.
I use the System.Web.Mail MailMessage class for this and then send my e-mail
through a smtp server.
The problem i have is with adding attachments. I use the following code

public void AddAttachment (string file)

{

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

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

{

message.Attachments.Add(bijlage);

}

}



Now when I use the debugger, my message (MailMessage) tells me it has an
attachment, but when I send the message the attachment is not sent with it.
So it shows up in my inbox, but without the attachment.

What am I doing wrong here??

Many thanks,



Bart
 
M

Mohamoss

Hi
Mostly the problem is that it does have an attachment object but that
object however doesn't refer to any file. Try to rewrite that part where
you add file to attachment object before adding that attachment object to
your message object.
For the code snippet that you submitted, I didn't see you adding
any file to the attachment object.
Try something like
bijlage.Items.Add("your file"))
hope that helps,
Mohamed M .Mahfouz
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC
 
B

Bart Stes

Hi,

Thanks for the info, but I thought that the MailAttachment class when it is
initialized with the filepath, IS the attachment. In my code "bijlage" is a
MailAttachment initialize with "file" (which is the path to the file I want
to attach). Furthermore bijlage doesn't have anything like Items.Add (it
doesn't have much at all).
 

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