Sending Emailing with an attachment

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Erm, as the subject title says... How do I manage to send emails with attachments in C#DOTNET, I've looked around for some example code, but the stuff I get is usually C#2003, and I'm running version C#2002, or, the examp[le code is buried under hordes of other code!!! Has anyone got a nice little class I could drop in there, or any examples with .NET Framework classes!?

I'm a newbie, so the easier to read, the better!!! ;) LO

Dab

:
 
Hi Dabz,
Erm, as the subject title says... How do I manage to send emails with
attachments in C#DOTNET, I've looked around for some example code,
but the stuff I get is usually C#2003, and I'm running version
C#2002, or, the examp[le code is buried under hordes of other code!!!
Has anyone got a nice little class I could drop in there, or any
examples with .NET Framework classes!?!

Ummm ... I'm working with VS.NET 2003 myself, but you should check the
classes in the System.Web.Mail-Namespace. There should be a MailMessage
class, which has an "Attachment"-Property. This property contains a List of
MailAttachment-Objects ... and these objects you'll have to create :-).

Regards,

Frank Eller
 
I've tried using this example, but I get a error message:

[CODE
http://support.microsoft.com/default.aspx?scid=kb;en-us;31027
[CODE

Error message is:

[ERROR
System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Re
lection.TargetInvocationException: Exception has been thrown by the target of a
invocation. ---> System.Runtime.InteropServices.COMException (0x80040211): Th
message could not be sent to the SMTP server. The transport error code was 0x80
40217. The server response was not availabl

--- End of inner exception stack trace --
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr
Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[
namedParameters
at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Bin
er binder, Object target, Object[] args, ParameterModifier[] modifiers, Culture
nfo culture, String[] namedParameters
at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String metho
Name, Object[] args
--- End of inner exception stack trace --
at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String metho
Name, Object[] args
at System.Web.Mail.CdoSysHelper.Send(MailMessage message
at System.Web.Mail.SmtpMail.Send(MailMessage message
at WebMail.Class1.Main(String[] args) in c:\documents and settings\michael\m
documents\visual studio projects\consoleapplication1\class1.cs:line 34 Excepti
n caught
Press any key to continu
[ERROR

Any idea's on what's going on, or will this too not work on C#.NET2002 too??

Dab

:
 
This should help http://www.knowdotnet.com/articles/smtp.html I don't think
I used an attachment in this example but .Attachement is just another
property and if I remember correctly, you just point it to the file
reference of what you want to attach,


HTH,

Bill

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
Dabz said:
Erm, as the subject title says... How do I manage to send emails with
attachments in C#DOTNET, I've looked around for some example code, but the
stuff I get is usually C#2003, and I'm running version C#2002, or, the
examp[le code is buried under hordes of other code!!! Has anyone got a nice
little class I could drop in there, or any examples with .NET Framework
classes!?!
 
mmmm, it should be working fine, everything seems to be there... bit of a bugger!!! :

The problem is, I cannot connect to my server...

* Dabz scratch's his head

Oh well, I'll just have to see what each functions returns, see if I can figure it out doing that!!! :

Dab

:
 
=?Utf-8?B?RGFieg==?= said:
System.Web.HttpException: Could not access 'CDO.Message' object. --->
System.Ref lection.TargetInvocationException: Exception has been thrown

SWM relies on CDO - which is one of the few reasons you should consider
something else.

Try this:
http://www.codeproject.com/useritems/IndySMTP.asp

There is an additional example to send an attachment in the newsgroup for it.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
 

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

Back
Top