用ASP发电子邮件
** CDONTS组件文字格式 : **
BodyFormat=0 html方式
BodyFormat=1 纯文本方式
设置编码:
MailFormat=0 MIME格式
MailFormat=1 连续的纯文本
objCDO.BodyFormat=0
objCDO.MailFormat=0
objCDO.To = sendto
objCDO.mailformat=0
objCDO.From = sender
objCDO.cc = cc
objCDO.Subject = subject
objCDO.AttachFile att_file
objCDO.Body = body
objCDO.Importance = 2
objCDO.Send
Set objCDO = Nothing
用ASP发电子邮件
1
2Dim strTo, strSubject, strBody 'Strings for recipient, subject, boby
3Dim objCDOMail 'The CDO object
4'First we'll read in the values entered
5strTo = Request.Form("to")
6'These would read the message subject and body if we let you enter it
7'strSubject = Request.Form("subject")
8'strBody = Request.Form("body")
9strSubject = "Sample E-mail sent from X-Bit!"
10' This is multi-lined simply for readability
11strBody = "This message was sent from a sample at X-Bit. "
12strBody = strBody & "It is used to show people how to send e-mail from an "
13strBody = strBody & "Active Server Page. If you did not request this "
14strBody = strBody & "e-mail yourself, your address was entered by one of "
15strBody = strBody & "our visitors. We do not store these e-mail addresses."
16strBody = strBody & " Please address all concerns to [email protected] ."
17
18'Ok we've got the values now on to the point of the script.
19
20'We just check to see if someone has entered anything into the to field.
21'If it's equal to nothing we show the form, otherwise we send the message.
22'If you were doing this for real you might want to check other fields too
23'and do a little entry validation like checking for valid syntax etc.
24If strTo = "" Then
1<form action="./email_cdo.asp" method="post">
2Enter your e-mail address:<br/>
3<input name="to" size="30" type="text"/>
4<!-- These would be used if we decided to let you edit them
5Subject:
6<INPUT TYPE="text" NAME="subject" SIZE="30"></INPUT><BR>
7
8Message:
9<TEXTAREA NAME="body" ROWS="10" COLS="40" WRAP="virtual"></TEXTAREA><BR>
10\-->
11<input type="submit" value="Send Mail!"/>
12</form>
1
2Else
3' Create an instance of the NewMail object.
4Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
5
6' Set the properties of the object
7objCDOMail.From = " [email protected] "
8objCDOMail.To = strTo
9objCDOMail.Subject = strSubject
10objCDOMail.Body = strBody
11
12' There are lots of other properties you can use.
13' You can send HTML e-mail, attachments, etc...
14' You can also modify most aspects of the message
15' like importance, custom headers, ...
16' Check the documentation for a full list as well
17' as the correct syntax.
18
19' Some of the more useful ones I've included samples of here:
20'objCDOMail.Cc = " [email protected]; [email protected] "
21'objCDOMail.Bcc = " [email protected];[email protected] "
22'objCDOMail.Importance = 1 '(0=Low, 1=Normal, 2=High)
23'objCDOMail.AttachFile "c:\file.txt", "file.txt"
24
25' Send the message!
26objCDOMail.Send
27
28' Set the object to nothing because it immediately becomes
29' invalid after calling the Send method.
30Set objCDOMail = Nothing
31
32Response.Write "Message sent to " & strTo & "!"
33End If