The CDONTS Component
When sending Email in ASP, you often need the support of a COM component. If you do not have a third-party Email component, you can use the CDONTS Email component provided by IIS itself. Using this component requires installing and starting the SMTP service. The component is named CDONTS.DLL, and it must be registered with RegSvr32 before use.
The CDONTS component provides a series of objects, including AddressEntry, Attachment, Attachments, Folder, Message, Messages, NewMail, Recipient, Recipients, and Session; the one we use most often is the NewMail object. Below are the methods and properties provided by the NewMail object:

Name
Function Format
Attach Add an attachment Sub AttachFile(Source, [FileName], [EncodingMethod])
AttachURL Add attachments and data in URL format Sub AttachURL(Source,ContentLocation, [ContentBase], [EncodingMethod])
BCC Recipient list separated by "," (blind carbon copy) String-type property
Body TextHTML String-type property
bodyformat Email body format 0:HTMl1:Text
CC Recipient list separated by "," (carbon copy) String-type property
ContentBase Base address used by the body in mail with attachments String-type property
ContentLocation Used by the body in mail with attachments String-type property
From Sender address of the mail String-type property
Importance Mail priority 0: 1 2:
Send Send mail Sub Send([From], [To], [Subject], [Body], [Importance]) See the context properties for each parameter
SetLocaleIDs Set the code page identifier of the new message Sub SetLocaleIDs(CodePageID As Long)
Subject Mail subject String-type property
To List of recipient addresses separated by "," String-type property
Value Value of any mail header String-type property
Version Version number of the current collection data object library () Read-only string-type property
When using the methods of these objects, bracketed parameters can be omitted.
Here is an example using ASP:
Dim MailObject
Set MailObject = Server.CreateObject("CDONTS.NewMail")
MailObject.Send "sender email address","recipient email address","subject","email body"
To send an attachment, you can do this:
Dim MailObject
Set MailObject = Server.CreateObject("CDONTS.NewMail")
att_fileName="full path of the attachment file"
f_name="file name"
MailObject.From="enter the sender address here"
MailObject.To="enter the recipient address here"
MailObject.Subject="enter the subject"
MailObject.Body="enter the body"
MailObject.AttachFile att_file,f_name
MailObject.Send
Note: to send mail, the IUSR_ user needs read/write permission on the x:\Inetpub\mailroot directory.
|
CDONTS component: you do not need to download it specially; Microsoft already provides it as long as the NT SMTP service is installed.
Next we use this component to build a customer survey feedback form (Webmail). The main form code is as follows:
Your name:
Email address:
Mail subject:
Your comments and suggestions:
post.asp
Send form
Send form
'The following is the mail body; all the letters on my guestbook were sent to me this way.
strBody = "===========Guestbook message===========" & vbCrLf
strBody = strBody & "Send time:" & Now() & vbCrLf
strBody = strBody & "From:" & Name & vbCrLf
strBody = strBody & "Email:" & Email & vbCrLf
strBody = strBody & "Message:" & Text & vbCrLf
strBody = strBody & "============ END ============="
Set myMail = Server.CreateObject("CDONTS.NewMail")
myMail.From = Email
myMail.To = "yourmailbox@mailhost.com"
myMail.Subject = Mailsubject
myMail.Body = StrBody
myMail.Send
Set myMail=Nothing
'When the Send method completes successfully, the NewMail object becomes invalid but is not removed from memory. You should set the invalid object to Nothing to remove it from memory, or reassign another NewMail object to it.
%>
Your mail has been sent successfully. Thank you for your comments and suggestions!
In addition, CDONTS also supports the following methods:
Set Mymail = CreateObject("CDONTS.NewMail")
Mymail.From = *** 'mailbox of the sender
Mymail.To = *** 'mailbox of the recipient
Mymail.CC = *** 'carbon copy
Mymail.BCC = *** 'blind carbon copy
Mymail.Subject = *** 'mail subject
Mymail.Body = *** 'mail body
'Set the priority: 0-unimportant, 1-normal, 2-important.
Mymail.Importance = 2
Mymail.Send
Set Mymail = Nothing
%>
Note: the *** string may be something you write in, or taken from the form using the Request method. In short, use it according to your purpose.
Check whether you have the SMTP service installed. The default OPTION PACK installation includes the SMTP service. After the SMTP service is installed, there will be a file called CDONTS.DLL in your system32 directory.
If you do not know whether your site supports it, just download the Webmail program from this site, upload it to your site and test it; if no error is reported, it is definitely supported. If you get the "Can't Create Objection" error, then I think any site with ASP enabled certainly supports it; if it does not, the administrator is simply too lazy.
How do I use the CDONTS component to send HTML-based mail?
Set MyMail2 = CreateObject("CDONTS.NewMail")
HTML = ""
HTML = HTML & ""
HTML = HTML & "Sending CDONTS Email Using HTML"
HTML = HTML & ""
HTML = HTML & ""
HTML = HTML & ""
HTML = HTML & "This is a test mail in html "
HTML = HTML & "Mail content here ... "
HTML = HTML & ""
HTML = HTML & ""
MyMail2.From= "somebody@somewhere.com"
MyMail2.To="nobody@somewhere.com"
MyMail2.Subject="Test mail in HTML"
MyMail2.BodyFormat=0
MyMail2.MailFormat=0
MyMail2.Body = HTML
MyMail2.Send
set MyMail2=nothing
%>
In short, just write it in standard HTML.
How do I use the CDONTS component to send mail with attachments?
Set MyMail3 = CreateObject("CDONTS.NewMail")
MyMail3.From= "somebody@nowhere.com"
MyMail3.To= "nobody@nowhere.com"
MyMail3.Cc="nobody2@nowhere.com"
MyMail3.Subject="This is a Test"
MyCDONTSMail3.AttachFile Server.MapPath("C:\inetpub\wwwroot\somedirectory\anyfile.txt")
MyBody2 = "Thank you!" & vbCrLf
MyBody2 = MyBody2 & "Your information will be send to me!" & vbCrLf
MyBody2 = MyBody2 & "Welcome in http://java2000.126.com !"
MyMail3.Body= MyBody2
MyMail3.Send
set MyMail3=nothing
%>
The Kunshan mold production management software does not include this component. Moges mold production management software is professional mold production management software.
|
|