Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up How to use CDONTS

    This code from http://toppopgames.com (online games)




    Well, a lot of people have been asking about CDONTS here of late, so I decided to write a quick post about it. I hope this is allowed... To start with, I'm going to cover the .To and .From properties.

    CDONTS (Collaborative Data Objects for Windows NT Server) provides objects that you can use to send e-mails from you lovely ASP. The CDONTS library exposes a top-level class that lets you the NewMail class which provides an easy-to-use set of methods and properties that allow you to reach put from you ASP pages and deliver a message to someone's inbox!

    CDONTS is designed to run on NT/win2k and does not require Exchange Server to run. However, if you do have Exchange Server on your system, it needs to be installing after IIS for the CDONTS library to be properly installed. If you don't have Exchange Server, you will have to be running the good ol'
    SMTP server that comes with IIS.

    So lets get dirty!


    Code:

    Set objEmail = Server.CreateObject("CDONTS.NewMail")
    objEmail.send "your_name@siteaddressr.com", "recipent_address@theirsiteaddress.com", "Hi-ho!", _
    "Hi! I sent this e-mail from an ASP page!! --- Me"
    Set objEmail = nothing
    There you, and e-mail sent in only three lines. Now lets break it down!

    This creates a NewMail object from the CDONTS library.

    Code:

    Set objEmail = Server.CreateObject("CDONTS.NewMail")

    Now we send the e-mail using the Send method. The first parameter is who the email is from, and second is who its to, the third is the subject line and last but not least is the body of the message!

    Code:

    objEmail.send = "your_name@siteaddressr.com", "recipent_address@theirsiteaddress.com", "Hi-ho!", _
    "Hi! I sent this e-mail from an ASP page!! --- Me"

    And then we release the resource of the object

    Code:

    Set objEmail = nothing


    The NewMail object has a few properties. Above we used it in its most simplest form

    objMail.Send sender, the recipent, the subject line, the message

    But lets expand it some by looking at more functions

    To Property
    The To property lets you specify who the email is to, rather self explanatory! The property has the following form

    Code:

    objEmail.to = reciepientemail(s)

    reciepientemail(s) would be replace with the email or emails of the people who you want to get the email address. Which would look like this;

    Code:

    objEmail.to = "blah@hotmail.com"

    and if you want it to go to more than one person, you would separate email address' using a semicolon like so;

    Code:

    objEmail.to = "blah@hotmail.com;blah@yahoo.com;bob@hotmail.com"

    So now the above code could like like this;

    Code:

    Set objEmail = Server.CreateObject("CDONTS.NewMail")
    objEmail.to = "blah@hotmail.com;blah@yahoo.com;bob@hotmail.com"
    objEmail.send "your_name@siteaddressr.com", , "Hi-ho!", _
    "Hi! I sent this e-mail from an ASP page!! --- Me"
    Set objEmail = nothing

    From Property
    The From property lets you, guess it, specify who the email is from. and it looks like this;

    Code:

    objEmail.From = emailAddressOfSender

    With the emailAddressOfSender being replaced with your email;

    Code:

    objEmail.From = "you@email.com"

    You can only include one sender in this property, so you cant have more using semicolons, and doing this will cause an error!

    So now our email code looks like this;

    Code:

    Set objEmail = Server.CreateObject("CDONTS.NewMail")
    objEmail.to = "blah@hotmail.com;blah@yahoo.com;bob@hotmail.com"
    objEmail.From = ""your_name@siteaddressr.com"
    objEmail.send , , "Hi-ho!", _
    "Hi! I sent this e-mail from an ASP page!! --- Me"
    Set objEmail = nothing


    Well, I think that will do for now, I'll add some more in a few hrs, gotta get some work done and make a living

    So far our code looks like;

    Code:

    Set objEmail = Server.CreateObject("CDONTS.NewMail")
    objEmail.to = "blah@hotmail.com;blah@yahoo.com;bob@hotmail.com"
    objEmail.From = ""your_name@siteaddressr.com"
    objEmail.send , , "Hi-ho!", _
    "Hi! I sent this e-mail from an ASP page!! --- Me"
    Set objEmail = nothing

    And we looked at the .To and .From, now we're going to over the .Subject and .Body properties.

    Subject Property
    This is getting rather repitive don't you think? The subject property lets you define the subject and looks, and you may have already guessed, like this;

    Code:

    objMail.Subject = TheSubject

    Thats easy enough, yeah? So with out subject line it would look lke this

    Code:

    objMail.Subject = "Hi-Ho"

    which makes our code look like so;

    Code:

    Set objEmail = Server.CreateObject("CDONTS.NewMail")
    objEmail.to = "blah@hotmail.com;blah@yahoo.com;bob@hotmail.com"
    objEmail.From = ""your_name@siteaddressr.com"
    objEmail.Subject = "Hi-ho!"
    objEmail.send , , , _
    "Hi! I sent this e-mail from an ASP page!! --- Me"
    Set objEmail = nothing

    Body Property
    Last but not least we come to the body section. This sets the text of the message, or HTML, which we'll look at soon. And it looks like this;

    Code:

    objMail.Body = BodyText

    When we add our body text for our email message, it looks like this;

    Code:

    objEmail.Body = "Hi! I sent this e-mail from an ASP page!! --- Me"

    And our code block;

    Code:

    Set objEmail = Server.CreateObject("CDONTS.NewMail")
    objEmail.to = "blah@hotmail.com;blah@yahoo.com;bob@hotmail.com"
    objEmail.From = ""your_name@siteaddressr.com"
    objEmail.Subject = "Hi-ho!"
    objEmail.Body = "Hi! I sent this e-mail from an ASP page!! --- Me"
    objEmail.send
    Set objEmail = nothing

    When writing the e-mail body, you might want to add some formatting. You can do this by using then chr function. If you would like a new line you could use;

    Code:

    chr(13)

    and for a tab, you can use;

    Code:

    chr(9)


    So lets make a body message a little longer and nicer to look at;


    Code:

    Set objEmail = Server.CreateObject("CDONTS.NewMail")
    objEmail.to = "blah@hotmail.com;blah@yahoo.com;bob@hotmail.com"
    objEmail.From = ""your_name@siteaddressr.com"
    objEmail.Subject = "Hi-ho!"
    theMess = "Hello!" & chr(13) & chr(12) _
    & chr(9) & "Thank you for submitting you e-mail address!!" & chr(13) & chr(13) _
    & chr(9) & "We hope you enjoyed you visit and please come back soon and tell your friends about it!!"
    objEmail.Body = theMess
    objEmail.send
    Set objEmail = nothing

    Now lets go over the code

    First we create an instance if the NewMail object;

    Code:

    Set objEmail = Server.CreateObject("CDONTS.NewMail")

    then we specify whom the message is to;

    Code:

    objEmail.to = "blah@hotmail.com;blah@yahoo.com;bob@hotmail.com"

    whom the message is from;

    Code:

    objEmail.From = ""your_name@siteaddressr.com"

    now the message subject;

    Code:

    objEmail.Subject = "objEmail.Subject = "Hi-ho!""

    And then the body of the e-mail is stored in a variable, which makes things easier in the future;

    Code:

    theMess = "Hello!" & chr(13) & chr(12) _
    & chr(9) & "Thank you for submitting you e-mail address!!" & chr(13) & chr(13) _
    & chr(9) & "We hope you enjoyed you visit and please come back soon and tell your friends about it!!"

    then we set the body property to the theMess variable;

    Code:

    objEmail.Body = theMess

    and we send it and free up the memory

    Code:

    objEmail.send
    Set objEmail = nothing

    And thats how you send an e-mail with CDONTS! But wait, there more!! Oh, with CDONTS you can do all kinds of things with!! Next post i'll the .CC, .BCC and .Importance properties!!


    Lets look at the .CC, .BCC and .Importance properties.

    CC Property
    This property allows you to specify recipients of the message that are not part of the main recipients. The CC resipients see the same message but are noted as CC recipients instead of To reciepients in the header of the email... I've alwas wondered why this is done?.
    Anyway, it looks likes this

    Code:

    objEmail.CC = CCList

    So lets send it to some real address'

    Code:

    objEmail.CC = "joe@oreosnbeer.com"

    And like teh .To command, we can define more than one address using semicolons;

    Code:

    objEmail.CC = "joe@oreosnbeer.com;jerry@oreosnbeer.com"

    Want to add it into our code? Nah, we'll leave that for a minute

    BBC Property
    CDONTS also allows you to send blind carbon copies of the email. A BCC addresse receives the same message as those specified in the .To and CC properties, but the .To and CC are unaware of the BBC e-mail address'. This allows you to privately include people to send the e-mail to;

    Code:

    objEmail.BCC = BCCList

    And it works the same as the .CC, so we'll jus send it to the same address'

    Code:

    objEmail.BCC = "joe@oreosnbeer.com;jerry@oreosnbeer.com"


    Importance Property
    In different e-mail applications they allow you to send and importance level with you email message. Tho it depends on the system how the importance flag is displayed. And the syntax is;

    Code:

    objEmail.Importance = Value

    The Value must be one of the following numbers;
    0 - Low Importance
    1 - Normal Importance (Default)
    2 - High Importance

    Unfortuantly, i gotta run, but the next post will have how to make the email HTML, and add attachments

    Ok, so the e-mail your sending is getting the basic message across, but its not very nice looking is it? So lets spice it up.

    We're now going to look at creating a HTML e-mail.

    BodyFormat and MailFormat Properties
    These two commands let you send HTML e-mails, which lets you more or less send HTML pages in your email

    First lets cover the bodyformat property, which looks like this:

    Code:

    objEmail.BodyFormat = Value

    Value can be set to 1, the default that means that body of the e-mail is boring old text. It can also be set to 0, which will you have HTML in the body!

    To actually send HTML e-mail, you also must use the MailFormat property like so:

    Code:

    objEmail.MailFormat = Value

    The value for this, like the BodyFormat Property, can be set to 1 or 0. The default value is 1, which means that the e-mail will be encoded as text, but changing it to, yup, you guesed it, 0. This will mean MIME encoding will be used.

    Now lets send a high priority HTML email:

    Code:

    Set objEmail = server.CreateObject("CDONTS.NewMail")
    objEmail.To = "tim@anywhere.com;bob@blah.com"
    objEmail.From = "you@yourname.com"
    objEmail.Subject = "New stuff on my site!"
    theMess = "<html>" _
    & "<head>" _
    & "<title>New stuff at my site!</title>" _
    & "</head>" _
    & "<body>" _
    & "<H1>We have just added new content to our site!!</H1>" _
    & "Yup, after a long a long time, we finally up dated out site!!</p>" _
    & "Click <a href=""www.toppopgames.com"">here</a> to find out more!" _
    & "</body>" _
    & "</html>"
    objMail.Body = theMess
    objEmail.Importance = 2
    objEmail.BodyFormat = 0
    objEmail.MailFormat = 0
    objEmail.send
    Set objEmail = nothing

    And there you go, how to send a HTML email with high importnace!
    Now, i know i said that i was going to cover how to add attachments, but I'm gong to have to leave that till later

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and if you want to pull yourself into this century then use CDO
    http://www.w3schools.com/asp/asp_send_email.asp

  • #3
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Woah, seriously, like degsy said, CDONTS is a thing of the past. You have to have a fairly old Windows server to be using CDONTS. CDOSYS, or CDO, comes as default with Windows Server 2000 and up and with Windows XP. CDOSYS is a bit more powerful and versatile. So yeah, although good intentions with the tutorial, sending email via CDONTS isn't quite that popular anymore and will soon be outdated.

    -Shane


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •