Cdo errors

  • Thread starter Thread starter chris
  • Start date Start date
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
 
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();
 
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
 
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.
 
Back
Top