msgbartop
世界上没有老实人,所谓的老实人是用来欺骗像我这样老实的人!
msgbarbottom

01 6月 06 用ASP发电子邮件

2006年6月01日发表于Net.Ru | 共有:0 人评论

用ASP发电子邮件

代码:
<%

Dim strTo, strSubject, strBody &#39;Strings for recipient, subject, boby

Dim objCDOMail &#39;The CDO object

&#39;First we&#39;ll read in the values entered

strTo = Request.Form(&#34;to&#34;)

&#39;These would read the message subject and body if we let you enter it

&#39;strSubject = Request.Form(&#34;subject&#34;)

&#39;strBody = Request.Form(&#34;body&#34;)

strSubject = &#34;Sample E-mail sent from X-Bit!&#34;

&#39; This is multi-lined simply for readability

strBody = &#34;This message was sent from a sample at X-Bit. &#34;

strBody = strBody &amp; &#34;It is used to show people how to send e-mail from an &#34;

strBody = strBody &amp; &#34;Active Server Page. If you did not request this &#34;

strBody = strBody &amp; &#34;e-mail yourself, your address was entered by one of &#34;

strBody = strBody &amp; &#34;our visitors. We do not store these e-mail addresses.&#34;

strBody = strBody &amp; &#34; Please address all concerns to pplo@sina.com.&#34;

&#39;Ok we&#39;ve got the values now on to the point of the script.

&#39;We just check to see if someone has entered anything into the to field.

&#39;If it&#39;s equal to nothing we show the form, otherwise we send the message.

&#39;If you were doing this for real you might want to check other fields too

&#39;and do a little entry validation lik&amp;#101; checking for valid syntax etc.

If strTo = &#34;&#34; Then

%>

<FORM ACTION=&#34;./email_cdo.asp&#34; METHOD=&#34;post&#34;>

Enter your e-mail address:<BR>

<INPUT TYPE=&#34;text&#34; NAME=&#34;to&#34; SIZE=&#34;30&#34;></INPUT>

<!– These would be used if we decided to let you edit them

Subject:

<INPUT TYPE=&#34;text&#34; NAME=&#34;subject&#34; SIZE=&#34;30&#34;></INPUT><BR>

Message:

<TEXTAREA NAME=&#34;body&#34; ROWS=&#34;10&#34; COLS=&#34;40&#34; WRAP=&#34;virtual&#34;></TEXTAREA><BR>

–>

<INPUT TYPE=&#34;submit&#34; VALUE=&#34;Send Mail!&#34;></INPUT>

</FORM>

<%

Else

&#39; Cr&#101;ate an instance of the NewMail object.

Set objCDOMail = Server.Cr&#101;ateObject(&#34;CDONTS.NewMail&#34;)

&#39; Set the properties of the object

objCDOMail.From = &#34;ppop@sina.com&#34;

objCDOMail.To = strTo

objCDOMail.Subject = strSubject

objCDOMail.Body = strBody

&#39; There are lots of other properties you can use.

&#39; You can send HTML e-mail, attachments, etc…

&#39; You can also mod&amp;#105;fy most aspects of the message

&#39; lik&amp;#101; importance, custom headers, …

&#39; Check the documentation for a full list as well

&#39; as the correct syntax.

&#39; Some of the more useful ones I&#39;ve included samples of here:

&#39;objCDOMail.Cc = &#34;kola100@163.com;kola100@163.com&#34;

&#39;objCDOMail.Bcc = &#34;wwew@sina.com;wwew@sina.com&#34;

&#39;objCDOMail.Importance = 1 &#39;(0=Low, 1=Normal, 2=High)

&#39;objCDOMail.AttachFile &#34;c:file.txt&#34;, &#34;file.txt&#34;

&#39; Send the message!

objCDOMail.Send

&#39; Set the object to nothing because it immediately becomes

&#39; invalid after calling the Send method.

Set objCDOMail = Nothing

Response.Write &#34;Message sent to &#34; &amp; strTo &amp; &#34;!&#34;

End If

%>

您的留言

*