Cdo errors

C

chris

hi i am trying to send a mail using C# and asp.net
but i get the following error,


object objMail = Server.CreateObject("CDO.Message");
objMail.From = "(e-mail address removed)";
objMail.To = "(e-mail address removed)";
objMail.Subject = "Simple mail test";


objMail.TextBody = "Hi there; this is a test from the web
server.";
objMail.Fields("urn:schemas:httpmail:importance").Value = 1;
objMail.Fields.Update();
objMail.();

'object' does not contain a definition for 'From'
'object' does not contain a definition for 'To'
'object' does not contain a definition for 'Subject'
and so on
.......

but this works fine in vb.net and asp.net

Dim objMail As Object = Server.CreateObject("CDO.Message")
objMail.From = "(e-mail address removed)"
objMail.To = "(e-mail address removed)"
objMail.Subject = "Simple mail test"


objMail.TextBody = "Hi there; this is a test from the web
server."
objMail.Fields("urn:schemas:httpmail:importance").Value = 1
objMail.Fields.Update()
objMail.()

what do i do?
is it possible to use the cdo.message in c#?
cause everywhere on the net i have seen code for vb.net only and not c#

thanx
Chris
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Chris,

C# does not support so called late binding - that is, when method names are
not checked at design time but the methods are called by name at run time.
Therefore, you should add the CDO type library as a yet another project
reference, use the new operator to create a CDO.Message instance and then
use the created instance like you did in VB .NET:

CDO.MessageClass message = new CDO.MessageClass();

message.From = from;
message.Sender = sender;
message.To = to;
message.Subject = subject;

message.TextBody = body;

message.Send();
 
C

chris

but there is no library called cdo.message in
project add reference. under .net tab
what do i do?
i added system.web.mail.but it cant find.
CDO.Message.
which is the library?

Chris



Dmitriy Lapshin said:
Hi Chris,

C# does not support so called late binding - that is, when method names are
not checked at design time but the methods are called by name at run time.
Therefore, you should add the CDO type library as a yet another project
reference, use the new operator to create a CDO.Message instance and then
use the created instance like you did in VB .NET:

CDO.MessageClass message = new CDO.MessageClass();

message.From = from;
message.Sender = sender;
message.To = to;
message.Subject = subject;

message.TextBody = body;

message.Send();

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

chris said:
hi i am trying to send a mail using C# and asp.net
but i get the following error,


object objMail = Server.CreateObject("CDO.Message");
objMail.From = "(e-mail address removed)";
objMail.To = "(e-mail address removed)";
objMail.Subject = "Simple mail test";


objMail.TextBody = "Hi there; this is a test from the web
server.";
objMail.Fields("urn:schemas:httpmail:importance").Value = 1;
objMail.Fields.Update();
objMail.();

'object' does not contain a definition for 'From'
'object' does not contain a definition for 'To'
'object' does not contain a definition for 'Subject'
and so on
......

but this works fine in vb.net and asp.net

Dim objMail As Object = Server.CreateObject("CDO.Message")
objMail.From = "(e-mail address removed)"
objMail.To = "(e-mail address removed)"
objMail.Subject = "Simple mail test"


objMail.TextBody = "Hi there; this is a test from the web
server."
objMail.Fields("urn:schemas:httpmail:importance").Value = 1
objMail.Fields.Update()
objMail.()

what do i do?
is it possible to use the cdo.message in c#?
cause everywhere on the net i have seen code for vb.net only and not c#

thanx
Chris
 
D

Dmitriy Lapshin [C# / .NET MVP]

The library is on the COM references tab. The IDE will automatically
generate the .NET Interop assembly for you when you reference the CDO
library from the "COM" tab.
 

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

Similar Threads


Top