473,395 Members | 1,516 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,395 software developers and data experts.

Sending Emailing with an attachment

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

:
Nov 16 '05 #1
6 1192
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" <an*******@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
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!!! ;) LOL

Dabz

:)

Nov 16 '05 #2
Hi Dabz,

Dabz wrote:
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
Nov 16 '05 #3
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(O bject obj, String metho
Name, Object[] args
--- End of inner exception stack trace --
at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject 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

:
Nov 16 '05 #4
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

:

Nov 16 '05 #5
P.S. Thanks a lot chappies, much appreciated!!! :

Dab

:

Nov 16 '05 #6
"=?Utf-8?B?RGFieg==?=" <an*******@discussions.microsoft.com> wrote in
news:8B**********************************@microsof t.com:
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/
Nov 16 '05 #7

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

Similar topics

1
by: Leon | last post by:
I am trying to send an email with an attachment. The problem is the attachment is stored in db where I have created a longblob field that contains the file so I have no idea how to specify the...
3
by: Paul Lamonby | last post by:
Hi, I am sending a file from the server as an email attachment. The file is being attached no problem and sending the email, but I get an error when I try to open it saying it is corrupt....
9
by: Bill | last post by:
I am trying to have the capability to email attachments. Specifically I want to be able to email a specific attachment that I name that may be a PDF document, text doc, etc. I already have a...
0
by: Dragos Marian Barbu | last post by:
Recently I tried to develop a function to help me sending e-mail messages with more than one attachment. Everything is working OK when I am sebding messages with one attachment, but when I try to...
4
by: Farooq Khan | last post by:
hi, i'm using CDONTS component for emailing through one of my web service like this // Start of code // 'email' is the CDONTS object name email.send(EmailFrom.ToString(), EmailTo.ToString(),...
6
by: Anuradha | last post by:
Dear All How can i send mails using vb.net Thanx all
2
by: nduerr | last post by:
I have a table with pdf files stored in an attachment data type field in a 2007 Access File. I would like to run a query that would select a group out of this table (easy part) then send the pdf...
3
by: raj200809 | last post by:
when i m sending mail i received error from symantec Antivirus" Your email message was unable to be sent because your mail server rejected the message 550-5.7.1 the ip you’re using to send mail is...
1
by: =?Utf-8?B?U2FpIFZhamph?= | last post by:
Hi I am trying to send a .pdf document as an email attachment using net.mail. This email is being sent by a windows service application. After i receive the email, and when i try to open the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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
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...

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.