Cdo errors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chris

    #1

    Cdo errors

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


    object objMail = Server.CreateOb ject("CDO.Messa ge");
    objMail.From = "chris@hotmail. com";
    objMail.To = "chris@hotmail. com";
    objMail.Subject = "Simple mail test";


    objMail.TextBod y = "Hi there; this is a test from the web
    server.";
    objMail.Fields( "urn:schemas:ht tpmail:importan ce").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.CreateOb ject("CDO.Messa ge")
    objMail.From = "chris@hotmail. com"
    objMail.To = "chris@hotmail. com"
    objMail.Subject = "Simple mail test"


    objMail.TextBod y = "Hi there; this is a test from the web
    server."
    objMail.Fields( "urn:schemas:ht tpmail:importan ce").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



  • Dmitriy Lapshin [C# / .NET MVP]

    #2
    Re: Cdo errors

    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.MessageClas s message = new CDO.MessageClas s();

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

    message.TextBod y = body;

    message.Send();

    --
    Dmitriy Lapshin [C# / .NET MVP]
    X-Unity Test Studio

    Bring the power of unit testing to VS .NET IDE

    "chris" <asdf@hotmail.c om> wrote in message
    news:ez9NLwVmDH A.2528@TK2MSFTN GP10.phx.gbl...[color=blue]
    > hi i am trying to send a mail using C# and asp.net
    > but i get the following error,
    >
    >
    > object objMail = Server.CreateOb ject("CDO.Messa ge");
    > objMail.From = "chris@hotmail. com";
    > objMail.To = "chris@hotmail. com";
    > objMail.Subject = "Simple mail test";
    >
    >
    > objMail.TextBod y = "Hi there; this is a test from the web
    > server.";
    > objMail.Fields( "urn:schemas:ht tpmail:importan ce").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.CreateOb ject("CDO.Messa ge")
    > objMail.From = "chris@hotmail. com"
    > objMail.To = "chris@hotmail. com"
    > objMail.Subject = "Simple mail test"
    >
    >
    > objMail.TextBod y = "Hi there; this is a test from the web
    > server."
    > objMail.Fields( "urn:schemas:ht tpmail:importan ce").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
    >
    >
    >[/color]

    Comment

    • chris

      #3
      Re: Cdo errors

      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 [C# / .NET MVP]" <x-code@no-spam-please.hotpop.c om> wrote
      in message news:eKsY9XXmDH A.2732@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Hi Chris,
      >
      > C# does not support so called late binding - that is, when method names[/color]
      are[color=blue]
      > 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.MessageClas s message = new CDO.MessageClas s();
      >
      > message.From = from;
      > message.Sender = sender;
      > message.To = to;
      > message.Subject = subject;
      >
      > message.TextBod y = 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" <asdf@hotmail.c om> wrote in message
      > news:ez9NLwVmDH A.2528@TK2MSFTN GP10.phx.gbl...[color=green]
      > > hi i am trying to send a mail using C# and asp.net
      > > but i get the following error,
      > >
      > >
      > > object objMail = Server.CreateOb ject("CDO.Messa ge");
      > > objMail.From = "chris@hotmail. com";
      > > objMail.To = "chris@hotmail. com";
      > > objMail.Subject = "Simple mail test";
      > >
      > >
      > > objMail.TextBod y = "Hi there; this is a test from the web
      > > server.";
      > > objMail.Fields( "urn:schemas:ht tpmail:importan ce").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.CreateOb ject("CDO.Messa ge")
      > > objMail.From = "chris@hotmail. com"
      > > objMail.To = "chris@hotmail. com"
      > > objMail.Subject = "Simple mail test"
      > >
      > >
      > > objMail.TextBod y = "Hi there; this is a test from the web
      > > server."
      > > objMail.Fields( "urn:schemas:ht tpmail:importan ce").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
      > >
      > >
      > >[/color]
      >[/color]


      Comment

      • Dmitriy Lapshin [C# / .NET MVP]

        #4
        Re: Cdo errors

        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.

        --
        Dmitriy Lapshin [C# / .NET MVP]
        X-Unity Test Studio

        Bring the power of unit testing to VS .NET IDE

        "chris" <ally@hotmail.c om> wrote in message
        news:en1UmPdmDH A.2012@TK2MSFTN GP12.phx.gbl...[color=blue]
        > 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[/color]

        Comment

        Working...