2022-12-26 07:43:13 來自:123.194.210.24
 回覆
1樓. 回覆 : 1281 時間 : 2022-12-27 10:12:22
ASP 基本的寄信功能,讓您的ASP網頁又有一個更強大的網站服務可用
ASP newmail object 傳送郵件功能
運用newmail功能,您可以簡單的透過ASP在Microsoft Windows NT server系統上傳送郵件訊息‧ 例如簡單的確認信等. 且很簡單! 可以直接在自己電腦上寄信...(with SMTP, actually)
我在這裡就直接教一下怎麼簡單的說怎麼利用他寄信好了....
=============================================
怎麼開始使用newmail object?
=============================================
有學過怎麼寫ASP + 資料庫的網友應該都知道,您必須使用createobject方式去"create an object"(這就是為什麼它叫createobject阿...) 例如:
set objconn = server.createobject("adodb.connection")
當然,要使用newmail object也要用到createobject...用法:
set mail = server.createobject("cdonts.newmail")
這就是第一步了....
=============================================
newmail 的 from property
=============================================
寫過信的話也許您會知道如果是英文信封,from就是寫寄件者的意思,在這邊的from也是相同的意思‧ 注意它的內容必須為一個string!建議填您的電子郵件...
延續上面的方式,再利用from寫個例子:
set mail = server.createobject("cdonts.newmail")
mail.from = "admin@xxx.com" '這行是from的用法
=============================================
newmail 的 to
=============================================
用法就跟from差不多,to 就填收信者的電子郵件‧
set mail = server.createobject("cdonts.newmail")
mail.to = "xxxx@yahoo.com.tw" '這一行是to的用法
=============================================
newmail 的 subject
=============================================
用法一樣,subject就是郵件主題的意思...
set mail = server.createobject("cdonts.newmail")
mail.subject = "恭喜您獲得獎金!"
=============================================
newmail 的 body
=============================================
用法一樣,在這裡body的意思是您的信件內容...
set mail = server.createobject("cdonts.newmail")
mail.body = "內容..."
=============================================
newmail 的 send
=============================================
當您上面的東西填完後,很簡單... send就直接寫
mail.send
郵件就會開始傳出去了.... send也有另一種用法:
objNewMail.Send( [From] [, To] [, Subject] [, Body] [, Importance] )
Importance的部份:
0 = Low importance
1 = Normal importance (default)
2 = High importance
_________________________________________________________________________________
一個範例: 直接寫的一個範例...可自己玩看看... 假設我的網站在申請會員上讓系統自己
幫我寄封申請會員後的信...
表單填寫畫面:(index.htm)
<meta http-equiv="Content-Language" content="zh-tw">
<form method="POST" action="confirm.asp">
<p>姓名<input type="text" name="name" size="16"><br>
線上匿名<input type="text" name="screenname" size="20"><br>
申請帳號<input type="text" name="account" size="20"><br>
申請密碼<input type="text" name="password" size="20"><br>
電子郵件<input type="text" name="email" size="20"></p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>
寄信頁(confirm.asp)
<%
body2 = "您好,"
body3 = "歡迎加入本站xx網站之會員‧此電子郵件包含了您的帳號,密碼"
body4 = "等其他訊息‧ 為了尊重您的網路隱私,請勿隨意的透露您的訊息!Tek"
body5 = "本網站 不會過問您在本站的私人資訊‧" & vbcrlf
body7 = "您的帳號為:"& Request.form("account") & vbcrlf
body8 = "您的密碼為:"& Request.form("password") & vbcrlf
body9 = "如有任何疑問,歡迎您電子郵件給站長:cx@ms74.url.com.tw" & vbcrlf
body10 = "xx網站 站長 敬上."
dim mail
set mail = server.createobject("cdonts.newmail")
mail.from = "admin@xxx.com"
mail.to = request.form("email")
mail.subject = "您好,歡迎您加入xx網站!"
mail.body = body2 & body3 & body4 & body5 & body6 & body7 & body8 & body9 & body10
mail.send
set mail = nothing
Response.write "謝謝您,您的重要訊息已經順利寄到您的信箱!"
%>
2樓. 回覆 : 1281 時間 : 2022-12-27 10:09:07
Using ASP it is easy to send emails.
- First you create the three required objects by saying:
1. Set <configuration_object_name> = CreateObject("CDO.Configuration")
2. Set <message_object_name> = CreateObject("CDO.Message")
3. Set <fields name> = <configuration_object_name>.Conf.Fields
- Define the Configuration
We control the configuration by setting the following values:
Const cdoSendUsingPickup = 1
With <fields name>
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPickup
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory")="<path of the pickup directory>"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "<SMTP server name>"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") =<number of seonds>
.Update
End With
For this example we will call: our email configuration "myMail"; the message "myMessage"; and the field name "myFields". For this server we then say:
Set myMailConfig = CreateObject("CDO.Configuration")
Set myMessage = CreateObject("CDO.Message")
Set myFields = myMail.Conf.Fields
Const cdoSendUsingPickup = 1
With myFields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPickup
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory")="c:Inetpubmailrootpickup"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "post-office.uh.edu"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
.Update
End With
In the above:
- the pickup directory is located on the server in the directory named: "c:Inetpubmailrootpickup"
- the SMPT server is: "post-office.uh.edu"
- we set the timeout in seconds as: 10
- Create and send the message
The following message fields are required:
- <message_object_name>.From ="<sender's email address>"
- <message_object_name>.To = "<recipient's email address>"
- <message_object_name>.Subject = "<some text>"
- <message_object_name>.TextBody ="<some plain text for the message body>"
OR
- <message_object_name>.HTMLBody ="<some text with HTML tags>"
OR
- Send a complete web page: <message_object_name>.CreateHTMLBody = "<URL of the web page>"
NOTE: this can be annoying if the web page is large
The following fields are optional:
For plain text (i.e., .TextBody) you can create line break by inserting the "carriage return/line feed" sequence by placing the two ASCII characters 10 (line feed) and 13 (carriage return) in the string like this:
"...we are at the end of the sentence."+chr(13)+chr(10)+"So this string starts on a new line"
The email body text would then appear as:
"...we are at the end of the sentence.
So this string starts on a new line"
The email message is created and sent by using the following code:
With <message_object_name>
Set .Configuration = <configuration_object_name>
.To = "<recipient's email address>"
.From = "<sender's email address>"
.Subject = "<some text>"
.TextBody = "<some text for the message body>"
.Send
End With
NOTE: you could send HTML rather than plain text by using .HTMLBody or .CreateHTMLBody rather than .TextBody
An example would be:
With myMessage
Set .Configuration = myMailConfig
.To = "carl.la.fong@gmail.com"
.From = "parks@uh.edu"
.Subject = "Greetings"
.TextBody = "...from the great state of Texas"
.Send
End With
- Clean up -- set the three objects we created to "nothing"
Set <message_object_name> = nothing
Set <configuration_object_name> = nothing
Set <fields name> = nothing
In our example this would be:
Set myMessage = nothing
Set myMailConfig = nothing
Set myFields = nothing
For this server here is a complete working example that you can cut and paste
CAUTION: Be VERY careful about using this feature. Run simple tests before you implement this. Misuse of CDO on this server (e.g., spamming a large number of recipients with emails IS NOT ALLOWED). Email are traceable and if you misuse this feature your account will be disabled -- no exceptions.