Asp Email using CDONTS

來源:互聯網
上載者:User
Using the CDONTS component to send email from ASP pages.

Many ASP programmers want to now know to do this and with the arrival of IIS4 and the SMTP service of Option Pack 4 it is now fairly easy. 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. Setting up the SMTP service properly is up to you. It is fairly self explanatory and I have never had any problems installing it. Any quality ISP's who offer ASP hosting should already have this set up on their servers.

The following three examples should give you the basic idea and get you started.

Using CDONTS to send a text based email message.

<%
    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 for ordering that stuff" & vbCrLf
    MyBody = MyBody & "We appretiate your business" & vbCrLf
    MyBody = MyBody & "Your stuff will arrive within 7 business days"
    MyCDONTSMail.Body= MyBody
    MyCDONTSMail.Send
    set MyCDONTSMail=nothing
%>

Using CDONTS to send a HTML based email message.

You'll get the general idea..notice how you have to add extra double quotes inside the HTML. You can use any valid HTML. Just make sure you link the images back to your webserver so that the recipient doesn't get a broken image. If the recipient's email program doesn't support HTML this is not always a good way to send email, but most do in my experience and if they don't they will still get the message... it will just look kinda strange.

<%
    Dim MyCDONTSMail2
    Dim HTML
    Set MyCDONTSMail2 = 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 & "<p><font size =""3"" face=""Arial""><strong>"
    HTML = HTML & "Name Of Store</strong><br>"
    HTML = HTML & "Incoming Customer Order</strong></p>"
    HTML = HTML & "<p align = ""center"">Bla Bla Bla Bla Bla</p>"
    HTML = HTML & "</body>"
    HTML = HTML & "</html>"
    MyCDONTSMail2.From= "somebody@somewhere.com"
    MyCDONTSMail2.To="nobody@somewhere.com"
    MyCDONTSMail2.Subject="Incoming Customer Order"
    MyCDONTSMail2.BodyFormat=0
    MyCDONTSMail2.MailFormat=0
    MyCDONTSMail2.Body=HTML
    MyCDONTSMail2.Send
    set MyCDONTSMail2=nothing
%>

Using CDONTS to send a file attachment and have a Carbon Copy Recipient.

<%
    Dim MyBody2
    Dim MyCDONTSMail3
%>

<%
    Set MyCDONTSMail3 = CreateObject("CDONTS.NewMail")
    MyCDONTSMail3.From= "somebody@nowhere.com"
    MyCDONTSMail3.To= "nobody@nowhere.com"
    MyCDONTSMail3.Cc="nobody2@nowhere.com"
    MyCDONTSMail3.Subject="This is a Test"

   
    MyCDONTSMail3.AttachFile Server.MapPath("/somedirectory/bla.txt")
    ' or you could specify the path exactly if you knew it like below
    'MyCDONTSMail3.AttachFile ("C:/inetpub/wwwroot/somedirectory/bla.txt")

    
    MyBody2 = "Thank you for ordering that stuff" & vbCrLf
    MyBody2 = MyBody2 & "We appretiate your business" & vbCrLf
    MyBody2 = MyBody2 & "Your stuff will arrive within 7 business days"
    MyCDONTSMail3.Body= MyBody2
    MyCDONTSMail3.Send
    set MyCDONTSMail3=nothing
%>

When sending an attachment this is just a very simple example. There are certain encoding options and file type settings that you may also want to set.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.