473,804 Members | 3,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,MailEncodi ng.Base64);

if (!message.Attac hments.Contains (bijlage))

{

message.Attachm ents.Add(bijlag e);

}

}

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 1477
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.A dd("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.microsof t.com> schreef in bericht
news:RY******** ******@TK2MSFTN GXA01.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.A dd("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("yo ur file")
"Bart Stes" <ba*******@tele net.be> wrote in message
news:kU******** *************@p hobos.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.microsof t.com> schreef in bericht
news:RY******** ******@TK2MSFTN GXA01.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.A dd("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
2450
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/) Everything is ok but if I use a specific e-mail address (say address X) in the field To, the e-mail arrives without attachments. (even if I use two addresses for field To, of which one is address X, the mail to address X arrives without attachments,...
4
8681
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 spreadsheet attachment per message, seems to be causing som kind of corruption of the attachment, while several spreadsheets per works just fine. Consider the following three snippets of C# code:
3
3881
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 when I deployed it on the production machine, it doesn't work. It gives me an error as below when I click send email button. And I tried to debug it. Seems like File field control's postedfile.filename is not working even I have
3
5690
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 question is, how to you set the Content-Location of each attachment in the mail headers so that the images are embedded in the html email rather than attached? This is my code:
5
1297
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 whats wrong? I'm testing this on a Win XP Pro SP2. I get the same error whether I specify a remote mail server like "mail.myserver.mydomain.com" or if I specify local. On the local machine I have IIS installed as well as Outlook 2003 and my mails...
2
4535
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 from using system.web.mail to system.net.mail (of course vs is telling me system.web.mail is obsolete). In .Net 1.1, the files deleted with no problem but in .Net 2 when I attempt to delete I receive The process cannot access the file ...'...
5
2373
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 files) or images (bmp, gif or tiff) I can send the email messages OK but the attachments are giving me grief. Can anyone provide some code that adds attachments to web mail messages. Thanks for any help,
4
1931
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 sent. I have no way of knowing whether an e-mail has or has not been sent, e.g. Line 34 in the below code will run regardless of whether the e-mail has been sent or not. Thank You P.S. Just for reference here's my code Dim strEmail As...
7
16933
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 line 522 and the code is: <?php /* $Id: email.php,v 1.12 2003/06/17 17:29:44 dgw_ Exp $
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10326
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10317
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7615
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.