TUTORIAL: using ASP CDONT mails

Discussion in 'C#' started by ludwig, Jul 13, 2008.

  1. #1
    • Sending ascii email using CDONT
    • Sending HTML email using CDONT
    • Sending attachments in email using CDONT

    Using CDONTS to send a simple ascii mail

    There is a component that is made available after the server installation of SMTP service.
    It is called CDONTS and it makes sending email rather easy.
    Considering that the SMTP service has been properly installed, it is fairly simple to use this feature.

    <%
    Dim MyBody
    Dim MyCDONTSMail
    Set MyCDONTSMail       = CreateObject("CDONTS.NewMail")
    MyCDONTSMail.From    = "somebody@nowhere.com"
    MyCDONTSMail.To          = "nobody@nowhere.com"
    MyCDONTSMail.Subject = "This is a Test"
    MyBody = "Thank you " & vbCrLf
    MyBody = MyBody & "Please do visit us again" & vbCrLf
    MyBody = MyBody & "Always at your service"
    MyCDONTSMail.Body= MyBody
    MyCDONTSMail.Send
    set MyCDONTSMail=nothing
    %> 	
    
    HTML:
    Using CDONTS to send a HTML based email message

    This is a simple program and I assume that you have a hang of HTML
    Note : If the recepient's email does not support HTML then this would not be a very good approach.
    <%
    Dim MyCDONTSMail
    Dim HTML
    Set MyCDONTSMail = CreateObject("CDONTS.NewMail")
    HTML = "<!DOCTYPE HTML PUBLIC""-//IETF//DTD HTML//EN"">"
    HTML = HTML & "<html>"
    HTML = HTML & "<head>"
    HTML = HTML & "<title>Sending CDONTS Email Using HTML</title>"
    HTML = HTML & "</head>"
    HTML = HTML & "<body bgcolor=""FFFFFF"">"
    HTML = HTML & "<font size =""3"" face=""Arial"">"
    HTML = HTML & "Name Of Store<br>"
    HTML = HTML & "Incoming Customer Order<br>"
    HTML = HTML & "<p align = ""center"">Bla Bla Bla Bla Bla</p>"
    HTML = HTML & "<body>"
    HTML = HTML & "<html>"
    MyCDONTSMail.From= "myself@myplace.com"
    MyCDONTSMail.To="toyou@urplace.com"
    MyCDONTSMail.Subject="Saying Hello"
    MyCDONTSMail.BodyFormat=0
    MyCDONTSMail.MailFormat=0
    MyCDONTSMail.Body=HTML
    MyCDONTSMail.Send
    set MyCDONTSMail=nothing
    %>
    
    HTML:
    Using CDONTS to send a file attachment and have a Carbon Copy Recipient.

    <%
    Dim MyBody
    Dim MyCDONTSMail
    
    Set MyCDONTSMail = CreateObject("CDONTS.NewMail")
    MyCDONTSMail.From= "somebody@nowhere.com"
    MyCDONTSMail.To= "nobody@nowhere.com"
    MyCDONTSMail.Cc="nobody2@nowhere.com"
    MyCDONTSMail.Subject="This is a Test"
    
    MyCDONTSMail.AttachFile Server.MapPath("/somedirectory/myfile.txt")
    ' or you could specify the path exactly if you knew it like below
    ' MyCDONTSMail.AttachFile "C:\inetpub\wwwroot\somedirectory\myfile.txt"
    MyBody = "Thank you" & vbCrLf
    MyBody = MyBody & "Please visit us again" & vbCrLf
    MyBody = MyBody & "Always at your service"
    MyCDONTSMail.Body= MyBody
    MyCDONTSMail.Send
    set MyCDONTSMail=nothing
    %>
    
    HTML:
     
    ludwig, Jul 13, 2008 IP
  2. saurabhj

    saurabhj Banned

    Messages:
    3,459
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This is really very basic codes but useful ones. Will surely help to ASP newbies. Thanks for share.
     
    saurabhj, Jul 14, 2008 IP
  3. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #3
    Sometimes newbies ask the same questions over and over, thus its better to have the answers ready for them :)
     
    ludwig, Jul 14, 2008 IP
  4. Jhar

    Jhar Peon

    Messages:
    318
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for posting - I have seen the send mail question over and over again in this forum...
     
    Jhar, Jul 14, 2008 IP