Complete example of asp cdo. Message sending email by shawl. Qiu

Source: Internet
Author: User


Complete example of asp cdo. Message sending email by shawl. Qiu

Purpose:
ASP no component sends email
You only need to modify a few options to use the directly applied function.

Note:
The main operations are encapsulated in two functions: one is the mail form (fcdoform), and the other is the mail operation (fcdosendmail)
In addition to the primary recipient, CC and BCC are supported.
Dynamically select text/html format, or both
Enter SMTP information dynamically
Whether to use SSL
Three verification methods are supported.

Note:
Currently, the attachment function is not supported, mainly because of restrictions on the server and client.
Server scripts cannot directly read client files.

Directory:
1. Main Content: two main functions and complete application code
2. Preview:

Shawl. Qiu
2006-09-11
Http://blog.csdn.net/btbtd

1. Main Content: two main functions and complete application code

    Linenum

  1. <H1 style = "text-align: center! Important; color: red! Important; "> Asp CDO. message: the complete instance sent by shawl. Qiu
  2. <H2 style = "float: Right! Important; margin: 0px; padding: 0px; "> <a href =" http://blog.csdn.net/btbtd "> shawl. Qiu </a> Code </H2>
  3. <%
  4. Dim maction, mfrom, MTO, MCC, mbcc, msubject, mbody
  5. Dim msmtp, mport, mtimeout, MSSL, Muser, mpwd
  6. Maction = "? Id = CDO"
  7. Mfrom = "shawlqiu@21cn.com"
  8. MTO = "shawl.qiu@gmail.com, btbtd@msn.com"
  9. MCC = "btbtd@yahoo.com.cn"
  10. Mbcc = "shawl. Qiu + 2@gmail.com"
  11. Msubject = "mail subject"
  12. Mbody = "test mail body" & CHR (13) & "" & CHR (13) & "<H2> HTML format </H2>"
  13. Msmtp = "smtp.21cn.com"
  14. Mport = 25
  15. Mtimeout = 60
  16. Muser = "shawlqiu"
  17. Mpwd = "don't tell you"
  18. Dim qid: qid = request. querystring ("ID ")
  19. Call fcdosendmail (qid, request. Form)
  20. If qid <> "CDO" then _
  21. Call fcdoform (maction, mfrom, MTO, MCC, mbcc, msubject, mbody, msmtp, mport, mtimeout, Muser, mpwd)
  22. Function fcdosendmail (RQs, rform)
  23. '''''''''''''''''''''''''''''''''''''''' '''''''''''
  24. 'Asp CDO. Message: complete email sending instance by shawl. Qiu
  25. 'Cdo email sending function fcdosendmail
  26. '''''''''''''''''''''''
  27. 'Parameter description:
  28. ''''''''''''''
  29. 'Rqs = request. querystring (ID)
  30. 'Rform = request. Form set
  31. '''''''''''''''''''''''
  32. 'Sample call:
  33. ''''''''''''''
  34. 'Call fcdosendmail (qid, request. Form)
  35. '''''''''''''''''''''''''''''''''''''''' '''''''''''
  36. If RQs = "" Or RQs <> "CDO" then exit function
  37. If isobject (rform) = false then exit function
  38. Dim temp
  39. For each temp in rform
  40. Select case temp
  41. Case "mtextbody"
  42. Case "mhtmlbody"
  43. Case "mfile"
  44. Case "MSSL"
  45. Case else
  46. Execute "dim" & temp & ":" & temp & "= request. Form (temp )"
  47. End select
  48. Next
  49. Dim MSSL, mtextbody, mhtmlbody
  50. MSSL = request. Form ("MSSL ")
  51. Mtextbody = request. Form ("mtextbody ")
  52. Mhtmlbody = request. Form ("mhtmlbody ")
  53. Mbody = "<meta http-equiv =" "Content-Type" "content =" "text/html; charset = gb2312" "/>" & CHR (13) & mbody
  54. If MSSL = "" Then MSSL = false else MSSL = true
  55. Dim CDO
  56. Set CDO = Createobject ("CDO. Message ")
  57. 'Configuration information for the remote SMTP Server
  58. With CDO. configuration. Fields
  59. . Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = msend
  60. . Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = msmtp 'smtp server address
  61. . Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = mport 'port 25
  62. . Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = muser' User Name
  63. . Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mpwd 'User Password
  64. . Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = mauth 'None, basic (base64 encoded), NTLM
  65. . Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = mtimeout' timeout settings, in seconds
  66. . Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = MSSL 'whether to use socket true/false
  67. . Update
  68. End
  69. With CDO
  70. . From = mfrom
  71. . To = MTO
  72. If MCC <> "then. Cc = MCC
  73. If mbcc <> "then. bcc = mbcc
  74. . Subject = msubject
  75. If mtextbody <> "then. textbody = mbody
  76. If mhtmlbody <> "then. htmlbody = mbody
  77. 'If Len (mfile)> 0 then. addattachment mfile
  78. '// CDO attachment sending rule: available variables for files in the current directory, not available variables in the current directory
  79. On Error resume next
  80. . Send
  81. If err. Number <> 0 then response. Write "failed to send the email, error no :"&_
  82. Err. Number & "<br/> error Description:" & err. Description else response. Write "email sent"
  83. End with 'shawl. Qiu Code'
  84. Set CDO = nothing
  85. End Function
  86. Function fcdoform (maction, mfrom, MTO, MCC, mbcc, msubject, mbody, msmtp, mport, mtimeout, Muser, mpwd)
  87. If maction = "" Then exit function
  88. '''''''''''''''''''''''''''''''''''''''' '''''''''''
  89. 'Asp CDO. Message: complete email sending instance by shawl. Qiu
  90. 'Cdo email sending form function fcdoform
  91. '''''''''''''''''''''''
  92. 'Parameter description: (except for maction, other parameter values are not required)
  93. ''''''''''''''
  94. 'Maction = form submission URL, such :? Id = CDO
  95. 'Mfrom = sender email
  96. 'Mto = recipient email
  97. 'Mcc = recipient email
  98. 'Mbcc = recipient email
  99. 'Msubject = Mail title
  100. 'Mbody = Email content
  101. 'Msmtp = SMTP server address, for example, smtp.21cn.com
  102. 'Mport = SMTP port, for example, 25
  103. 'Mtimeout = timeout limit, for example, 60 (unit: seconds)
  104. 'Muser = User Name
  105. 'Mpwd = Password
  106. '''''''''''''''''''''''
  107. 'Sample call:
  108. ''''''''''''''
  109. 'Dim maction, mfrom, MTO, MCC, mbcc, msubject, mbody
  110. 'Dim msmtp, mport, mtimeout, MSSL, Muser, mpwd
  111. 'Maction = "? Id = CDO"
  112. 'Mfrom = "shawlqiu@21cn.com"
  113. 'Mto = "shawl.qiu@gmail.com, btbtd@msn.com"
  114. 'Mcc = "btbtd@yahoo.com.cn"
  115. 'Mbcc = "shawl. Qiu + 2@gmail.com"
  116. 'Msubject = "mail subject"
  117. 'Mbody = "test mail body" & CHR (13) & "" & CHR (13) & "<H2> HTML format </H2>"
  118. 'Msmtp = "smtp.21cn.com"
  119. 'Mport = 25
  120. 'Mtimeout = 60
  121. 'Muser = "shawlqiu"
  122. 'Mpwd = "yourpassword"
  123. 'Call fcdoform (maction, mfrom, MTO, MCC, mbcc, msubject, mbody, msmtp, mport, mtimeout, Muser, mpwd)
  124. '''''''''''''''''''''''''''''''''''''''' '''''''''''
  125. %>
  126. <Form action = "<% response. Write maction %>" method = "Post" name = "mcdo">
  127. <P> from:
  128. <Input name = "mfrom" type = "text" value = "<% response. Write mfrom %>" size = "50%"/> <br/>
  129. To: <input name = "MTO" type = "text" value = "<% response. Write MTO %>" size = "50%"/>
  130. <Br/>
  131. Cc: <input name = "MCC" type = "text" value = "<% response. Write MCC %>" size = "50%"/> <br/>
  132. BCC: <input name = "mbcc" type = "text" id = "mbcc" value = "<% response. write mbcc %> "size =" 50% "type =" codeph "text ="/codeph "/> <br/>
  133. Subject: <input name = "msubject" type = "text" value = "<% response. Write msubject %>" size = "50%"/> <br/>
  134. Email format:
  135. Text: <input type = "checkbox" name = "mtextbody" value = "yes" Checked = "checked"/>
  136. HTML: <input type = "checkbox" name = "mhtmlbody" value = "yes"/> <br/>
  137. Text: <br/> <textarea name = "mbody" Cols = "77" rows = "10"> <% response. Write mbody %> </textarea> <br/>
  138. Remote SMTP: <input name = "msmtp" type = "text" value = "<% response. Write msmtp %>"/>
  139. Port: <input name = "mport" type = "text" value = "<% response. Write mport %>" size = "5"/>
  140. Timeout: <input name = "mtimeout" type = "text" value = "<% response. Write mtimeout %>" size = "5"/>
  141. Sec ssl: <input type = "checkbox" name = "MSSL" value = "ture"/> <br/>
  142. Username: <input name = "Muser" type = "text" value = "<% response. Write Muser %>"/> <br/>
  143. Password: <input name = "mpwd" type = "password" value = "<% response. Write mpwd %>"/> <br/>
  144. SMTP verification options:
  145. <Select name = "mauth">
  146. <Option value = "0"> Anonymous Authentication </option>
  147. <Option value = "1" selected = "selected"> general verification </option>
  148. <Option value = "2"> NTLM verification </option>
  149. </SELECT>
  150. Email sending options:
  151. <Select name = "msend">
  152. <Option value = "1"> send using pickup </option>
  153. <Option value = "2" selected = "selected"> send using port </option>
  154. </SELECT>
  155. <Br/>
  156. <Input type = "Submit" value = "Submit"/> <input type = "reset" value = "reset"/>
  157. </Form> <! -- Shawl. Qiu code -->
  158. <% End function %> <br/>
  159. <A href = "? "> Back </a>

2. Preview:

 

Complete example of asp cdo. Message sending email by shawl. qiushawl. Qiu code


Back


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.