473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

problem with Mail attachments

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
Nov 17 '05 #1
3 1461
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

Nov 17 '05 #2
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).

"Mohamoss" <mo************@egdsc.microsoft.com> schreef in bericht
news:RY**************@TK2MSFTNGXA01.phx.gbl...
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

Nov 17 '05 #3
if bijlage is a MailAttachment class then try

bijlage.Add("your file")
"Bart Stes" <ba*******@telenet.be> wrote in message
news:kU*********************@phobos.telenet-ops.be...
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).

"Mohamoss" <mo************@egdsc.microsoft.com> schreef in bericht
news:RY**************@TK2MSFTNGXA01.phx.gbl...
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


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: S_p_ike | last post by:
Hi all, I have a problem with mail with attachments. To send e-mail with attachments from a form, I use Setec Astronomy's libmail class (v 1.4) (available here http://www.phpclasses.org/) ...
4
by: Trond A. S. Andersen | last post by:
Hi, all! I'm trying to use the System.Web.Mail. "package" combinded with System.Web.Mail.SmtpMail in order to send MS Excel spreadsheets attached to mail messages. However, sending one single...
3
by: huan | last post by:
Hi, I am creating a function using C# to send emails with attachment file. And I am using File Field control to get file for attachment. Sending email works fine on development machine, however...
3
by: Tim T | last post by:
Hi, I hope there is someone reading this that has the answer, Please Help! I have the need to send a html email via asp.net. its easy enough to send an html email and add attachments. My...
5
by: RD | last post by:
In the following code, wen I get to SmtpMail.Send(myMessage) I get an exception cast is invalid. I single step through the code and everuthing is Ok till I execute that line. Can anyone tell me...
2
by: Brad | last post by:
I have a web .Net app which sends emails with attachments. After the email is sent I clean up aftermyself and delete the attachments from disk. In upgrading to .Net 2 I changed the email logic...
5
by: Robert Dufour | last post by:
I am trying to use framework 1.1 - stuck with it. to send emails from a windows form application. The email messages can have attachments, usually two and they can be either text or sounds (wav...
4
by: iheartvba | last post by:
Hi I have been able to successfully send e-mails using MS Outlook via MS Access. However I can't seem to find any error logging techniques. What I want to do is create a log of any e-mails actually...
7
by: mukeshrasm | last post by:
Hi I am no able to send mail and it is giving this error Warning: mail(): SMTP server response: 530 5.7.3 Client was not authenticated in c:\inetpub\wwwroot\eshop\includes\classes\email.php on...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.