1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Sending e-mail in ASP with CDOSYS

Discussion in 'ASP' started by pradeep, Oct 7, 2006.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:

    Introduction



    CDOSYS is a built-in component in ASP. This component is used to send e-mails with ASP.

    Sending e-mail with CDOSYS



    CDO (Collaboration Data Objects) is a Microsoft technology that is designed to simplify the creation of messaging applications.
    CDOSYS is a built-in component in ASP. We will show you how to use this component to send e-mail with ASP.

    How about CDONTs?



    Microsoft has discontinued the use of CDONTs on Windows 2000, Windows XP and Windows 2003. If you have used CDONTs in your ASP applications, you should update the code and use the new CDO technology.

    Examples using CDOSYS
    Sending a text e-mail:

    Code:
    <%
      
      Set myMail=CreateObject("CDO.Message")
      
      myMail.Subject="Sending email with CDO"
      
      myMail.From="mymail@mydomain.com"
      
      myMail.To="someone@somedomain.com"
      
      myMail.TextBody="This is a message."
      
      myMail.Send
      
      set myMail=nothing
      
      %>
      
    Sending a text e-mail with Bcc and CC fields:

    Code:
    <%
      
      Set myMail=CreateObject("CDO.Message")
      
      myMail.Subject="Sending email with CDO"
      
      myMail.From="mymail@mydomain.com"
      
      myMail.To="someone@somedomain.com"
      
      myMail.Bcc="someoneelse@somedomain.com"
      
      myMail.Cc="someoneelse2@somedomain.com"
      
      myMail.TextBody="This is a message."
      
      myMail.Send
      
      set myMail=nothing
      
      %>
    Sending an HTML e-mail:

    Code:
    <%
      
      Set myMail=CreateObject("CDO.Message")
      
      myMail.Subject="Sending email with CDO"
      
      myMail.From="mymail@mydomain.com"
      
      myMail.To="someone@somedomain.com"
      
      myMail.HTMLBody = "<h1>This is a message."
      
      myMail.Send
      
      set myMail=nothing
      
      %>
    Sending an HTML e-mail that sends a webpage from a website:

    Code:
    <%
      
      Set myMail=CreateObject("CDO.Message")
      
      myMail.Subject="Sending email with CDO"
      
      myMail.From="mymail@mydomain.com"
      
      myMail.To="someone@somedomain.com"
      
      myMail.CreateMHTMLBody "http://www.go4expert.com"
      
      myMail.Send
      
      set myMail=nothing
      
      %>
    Sending an HTML e-mail that sends a webpage from a file on your computer:

    Code:
    <%
      
      Set myMail=CreateObject("CDO.Message")
      
      myMail.Subject="Sending email with CDO"
      
      myMail.From="mymail@mydomain.com"
      
      myMail.To="someone@somedomain.com"
      
      myMail.CreateMHTMLBody "file://c:/mydocuments/go4expert.htm"
      
      myMail.Send
      
      set myMail=nothing
      
      %>
      
    Sending a text e-mail with an Attachment:

    Code:
    <%
      
      Set myMail=CreateObject("CDO.Message")
      
      myMail.Subject="Sending email with CDO"
      
      myMail.From="mymail@mydomain.com"
      
      myMail.To="someone@somedomain.com"
      
      myMail.TextBody="This is a message."
      
      myMail.AddAttachment "c:\mydocuments\go4expert.txt"
      
      myMail.Send
      
      set myMail=nothing
      
      %>
    Sending a text e-mail using a remote server:

    Code:
    <%
      
      Set myMail=CreateObject("CDO.Message")
      
      myMail.Subject="Sending email with CDO"
      
      myMail.From="mymail@mydomain.com"
      
      myMail.To="someone@somedomain.com"
      
      myMail.TextBody="This is a message."
      
      myMail.Configuration.Fields.Item _
      
      ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
      
      'Name or IP of remote SMTP server
      
      myMail.Configuration.Fields.Item _
      
      ("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
      
      ="smtp.server.com"
      
      'Server port
      
      myMail.Configuration.Fields.Item _
      
      ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
      
      =25
      
      myMail.Configuration.Fields.Update
      
      myMail.Send
      
      set myMail=nothing
      
      %>
     
  2. faital

    faital Guest

    Hi, This post is very informative, however I would like some specific information. If someone can help me then please send me a private message. Best Regards,
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    Why PM? You can just post it here or in the forums section. If its something very personal you cannot discuss here you can use the PM.
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    What specific information do you require faital?? Let me know!
     
  5. pushthelimits

    pushthelimits New Member

    Joined:
    Aug 8, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    could you please give an idea how to send a mail using cdosys
    using the folllowing code?


    <%

    Set myMail=CreateObject("CDO.Message")

    myMail.Subject="Sending email with CDO"

    myMail.From="mymail@mydomain.com"

    myMail.To="someone@somedomain.com"

    myMail.TextBody="This is a message."

    myMail.Send

    set myMail=nothing

    %>
    i have a page say 1.asp ,if i click a send button on 1.asp, it will go to 2.asp wer this code is written.

    i couldnt find the correct solution frm books and net, i tried a lot, no error is coming but mail is not sent.



    am using asp ,msaccess for this project.
    i have taken a asp connection/space from spaceforhost webhosting company.
    when i enquired they told cdosys is supported by them.

    is there any need of special server settings to run the code?
     

Share This Page