如何利用asp做一个发送邮件的程序?(5分)

  • 主题发起人 主题发起人 青云
  • 开始时间 开始时间

青云

Unregistered / Unconfirmed
GUEST, unregistred user!
比如我要发一个邮件给某个人。
不要设置pop3和smtp, 直接发送就行了
 
在服务器上创建cdo对象, 例子如下:
<%
'Óʼþ·¢Ëͺ¯Êý
Sub SendMail(AMailTo,AMailFrom,ASubject,AContent)

Const cdoSendUsingMethod="http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort=2
Const cdoSMTPServer="http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort="http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout="http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate="http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic=1
Const cdoSendUserName="http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword="http://schemas.microsoft.com/cdo/configuration/sendpassword"

Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields
Dim BodyParts 'As IBodyPart,

Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields

With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "smtp.sina.com.cn" '¸Ä³É¿ÉÓõÄÍⲿÓʼþ·þÎñÆ÷ÓòÃû
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "jb973@sina.com.cn" 'ÒÔÉÏ·þÎñÆ÷µÄÓû§Ãû
.Item(cdoSendPassword) = "111111" 'ÃÜÂë
.Update
End With

Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig

Set BodyPart = objMessage.BodyPart
BodyPart.Fields("urn:schemas:mailheader:content-type") = "text/plain"
BodyPart.Charset = "gb2312"
BodyPart.Fields.Update

ASubject= ASubject+ " ---(À´×Ôjb973ͬѧ¼)"
AContent= AContent &chr(13)_
&"----------------------------" &chr(13)_
& "¹ØÓÚͬѧ¼×î½üµÄÇé¿ö£¬Çë·ÃÎÊ£º http://jb973.126.com" &chr(13)_
& Now()

With objMessage
.To= AMailTo '½ÓÊÕÕßµÄÓʼþµØÖ·
.From= AMailFrom '·¢ËÍÈ˵ÄÓʼþµØÖ·
.Subject= ASubject '±êÌâ
.TextBody= AContent 'ÕýÎÄ
.send
End With

Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing

End Sub
%>
 
后退
顶部