ASP常用發送郵件的四個FUNCTION
代码
<%
'=====================================================================================================
'使用Jmail發送郵件,發送成功返回True,發送失敗返回false,jmail使用的端口是25,且不支持ssl方式
'參數說明:
'EmailFrom__: 發送郵件的郵箱
'EmailID__: 發送郵件的郵箱帳號
'EmailPWD__: 發送郵件的郵箱密碼
'EmailSMTP__: 發送郵件的SMTP SERVER
'EmailCharset__: 字符集
'EmailFormName__: 發送郵件郵箱的名稱
'ToEmail__: 發送的郵件地址
'Subject__: 郵件主題
'MailBody__: 郵件內容
'AttachFile__: 郵件附件
'=====================================================================================================
Function JMail(EmailFrom__,EmailID__,EmailPWD__,EmailSMTP__,EmailCharset__,EmailFormName__,ToEmail__,Subject__,MailBody__,AttachFile__)
On Error Resume Next
dim obj,MyArray,i
JMail=false
Set obj=Server.CreateObject("JMail.Message")
obj.silent=true'屏蔽列外錯誤
obj.logging=true''不記錄日志
obj.ContentTransferEncoding="base64"
obj.Charset=EmailCharset__
obj.ContentType = "text/html"
obj.MailServerUserName = EmailID__ '您的郵件服務器登錄名
obj.MailServerPassword = EmailPWD__ '登錄密碼
obj.MailDomain=EmailSMTP__
obj.Priority = 3
obj.From=EmailFrom__
obj.FromName=EmailFormName__
MyArray=Split(ToEmail__,";")
For i=0 to Ubound(MyArray)
obj.AddRecipient MyArray(i)
Next
obj.Subject__=Subject__
obj.Body=MailBody__
if AttachFile__<>"" then JMail.AddAttachment(AttachFile__)
if obj.Send(EmailSMTP__) then JMail=true
obj.Close()
Set obj=nothing
End Function
'=====================================================================================================
'使用CDONTS發送郵件,發送成功返回true,發送失敗返回false
'參數說明:
'EmailFrom__: 發送郵件的郵箱
'ToEmail__: 發送的郵件地址
'Subject__: 郵件主題
'MailBody__: 郵件內容
'AttachFile__: 郵件附件
'=====================================================================================================
Function Cdonts(EmailFrom__,ToEmail__,Subject__,MailBody__,AttachFile)
On Error Resume Next
Cdonts=true
dim obj
Set obj = Server.CreateObject("CDONTS.NewMail")
obj.From =EmailFrom__
obj.To =ToEmail__
obj.Subject =Subject__
obj.BodyFormat = 0
obj.MailFormat = 0
obj.Body =MailBody__
if AttachFile__<>"" then obj.AttachFile AttachFile__
obj.Send
Set obj = Nothing
If err then Cdonts=false
End Function
'=====================================================================================================
'使用Persits.MailSender發送郵件,發送成功返回true,發送失敗返回false
'參數說明:
'EmailFrom__: 發送郵件的郵箱
'EmailID__: 發送郵件的郵箱帳號
'EmailPWD__: 發送郵件的郵箱密碼
'EmailSMTP__: 發送郵件的SMTP SERVER
'EmailCharset__: 字符集
'EmailFormName__: 發送郵件郵箱的名稱
'ToEmail__: 發送的郵件地址
'Subject__: 郵件主題
'MailBody__: 郵件內容
'AttachFile__: 郵件附件
'=====================================================================================================
Function AspEmail(EmailFrom__,EmailID__,EmailPWD__,EmailSMTP__,EmailCharset__,EmailFormName__,ToEmail__,Subject__,MailBody__,AttachFile__)
On Error Resume Next
AspEmail=true
dim obj
Set obj=Server.CreateObject("Persits.MailSender")
obj.Charset = EmailCharset__
obj.IsHTML = True
obj.username = EmailID__ '服務器上有效的用戶名
obj.password = EmailPWD__ '服務器上有效的密碼
obj.Priority = 1
obj.Host = EmailSMTP__
obj.Port = 25 ' 該項可選.端口25是默認值
obj.From = EmailFrom__
obj.FromName = EmailFormName__ ' 該項可選
obj.AddAddress ToEmail__'需要以,分開
obj.Subject = Subject__
obj.Body = MailBody__
if AttachFile__<>"" then obj.AddAttachment AttachFile__
obj.Send
If err then AspEmail=false
End Function
'=====================================================================================================
'使用Persits.MailSender發送郵件,發送成功返回true,發送失敗返回false
'help link http://msdn.microsoft.com/en-us/library/ms872547(v=EXCHG.65).aspx
'參數說明:
'EmailFrom__: 發送郵件的郵箱
'EmailID__: 發送郵件的郵箱帳號
'EmailPWD__: 發送郵件的郵箱密碼
'EmailSMTP__: 發送郵件的SMTP SERVER
'EmailSMTPPROT__: 發送郵件使用的端口//default is 25, gmail smtp is 465 or 587 , gmail pop3 995
'EmailSSL__: 是否使用套接字傳送
'EmailCharset__: 字符集
'ToEmail__: 發送的郵件地址
'Subject__: 郵件主題
'MailBody__: 郵件內容
'AttachFile__: 郵件附件
'=====================================================================================================
Function CDO(EmailFrom__,EmailID__,EmailPWD__,EmailSMTP__,EmailSMTPPROT__,EmailSSL__,EmailCharset__,ToEmail__,Subject__,MailBody__,AttachFile__)
'On Error Resume Next
CDO=True
Const cdoSendUsingMethod="http://schemas.microsoft.com/cdo/configuration/sendusing"
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 cdoSendUserName="http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword="http://schemas.microsoft.com/cdo/configuration/sendpassword"
Const cdoSendSmtpUsessl="http://schemas.microsoft.com/cdo/configuration/smtpusessl"
Const cdoSendLanguageCode="http://schemas.microsoft.com/cdo/configuration/languagecode"
Const cdoSendUsingPort=2
Const cdoBasic=1
'//value=0 代表Anonymous驗證方式(不需要驗證)
'//value=1 代表Basic驗證方式(使用basic (clear-text) authentication.
'//The configuration sendusername/sendpassword or postusername/postpassword fields are used to specify credentials.)
'//Value=2 代表NTLM驗證方式(Secure Password Authentication in Microsoft Outlook Express)
Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = EmailSMTP__
.Item(cdoSMTPServerPort) = EmailSMTPPROT__
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = EmailID__
.Item(cdoSendPassword) = EmailPWD__
.Item(cdoSendSmtpUsessl) = EmailSSL__
.Update
End With
Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig
With objMessage
.BodyPart.Charset = EmailCharset__
.To = ToEmail__
.From = EmailFrom__
.Subject = Subject__
.HtmlBody = MailBody__
End With
If AttachFile__<>"" then objMessage.AddAttachment AttachFile__
objMessage.Send
If err then CDO=false
Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
End Function
%>
'=====================================================================================================
'使用Jmail發送郵件,發送成功返回True,發送失敗返回false,jmail使用的端口是25,且不支持ssl方式
'參數說明:
'EmailFrom__: 發送郵件的郵箱
'EmailID__: 發送郵件的郵箱帳號
'EmailPWD__: 發送郵件的郵箱密碼
'EmailSMTP__: 發送郵件的SMTP SERVER
'EmailCharset__: 字符集
'EmailFormName__: 發送郵件郵箱的名稱
'ToEmail__: 發送的郵件地址
'Subject__: 郵件主題
'MailBody__: 郵件內容
'AttachFile__: 郵件附件
'=====================================================================================================
Function JMail(EmailFrom__,EmailID__,EmailPWD__,EmailSMTP__,EmailCharset__,EmailFormName__,ToEmail__,Subject__,MailBody__,AttachFile__)
On Error Resume Next
dim obj,MyArray,i
JMail=false
Set obj=Server.CreateObject("JMail.Message")
obj.silent=true'屏蔽列外錯誤
obj.logging=true''不記錄日志
obj.ContentTransferEncoding="base64"
obj.Charset=EmailCharset__
obj.ContentType = "text/html"
obj.MailServerUserName = EmailID__ '您的郵件服務器登錄名
obj.MailServerPassword = EmailPWD__ '登錄密碼
obj.MailDomain=EmailSMTP__
obj.Priority = 3
obj.From=EmailFrom__
obj.FromName=EmailFormName__
MyArray=Split(ToEmail__,";")
For i=0 to Ubound(MyArray)
obj.AddRecipient MyArray(i)
Next
obj.Subject__=Subject__
obj.Body=MailBody__
if AttachFile__<>"" then JMail.AddAttachment(AttachFile__)
if obj.Send(EmailSMTP__) then JMail=true
obj.Close()
Set obj=nothing
End Function
'=====================================================================================================
'使用CDONTS發送郵件,發送成功返回true,發送失敗返回false
'參數說明:
'EmailFrom__: 發送郵件的郵箱
'ToEmail__: 發送的郵件地址
'Subject__: 郵件主題
'MailBody__: 郵件內容
'AttachFile__: 郵件附件
'=====================================================================================================
Function Cdonts(EmailFrom__,ToEmail__,Subject__,MailBody__,AttachFile)
On Error Resume Next
Cdonts=true
dim obj
Set obj = Server.CreateObject("CDONTS.NewMail")
obj.From =EmailFrom__
obj.To =ToEmail__
obj.Subject =Subject__
obj.BodyFormat = 0
obj.MailFormat = 0
obj.Body =MailBody__
if AttachFile__<>"" then obj.AttachFile AttachFile__
obj.Send
Set obj = Nothing
If err then Cdonts=false
End Function
'=====================================================================================================
'使用Persits.MailSender發送郵件,發送成功返回true,發送失敗返回false
'參數說明:
'EmailFrom__: 發送郵件的郵箱
'EmailID__: 發送郵件的郵箱帳號
'EmailPWD__: 發送郵件的郵箱密碼
'EmailSMTP__: 發送郵件的SMTP SERVER
'EmailCharset__: 字符集
'EmailFormName__: 發送郵件郵箱的名稱
'ToEmail__: 發送的郵件地址
'Subject__: 郵件主題
'MailBody__: 郵件內容
'AttachFile__: 郵件附件
'=====================================================================================================
Function AspEmail(EmailFrom__,EmailID__,EmailPWD__,EmailSMTP__,EmailCharset__,EmailFormName__,ToEmail__,Subject__,MailBody__,AttachFile__)
On Error Resume Next
AspEmail=true
dim obj
Set obj=Server.CreateObject("Persits.MailSender")
obj.Charset = EmailCharset__
obj.IsHTML = True
obj.username = EmailID__ '服務器上有效的用戶名
obj.password = EmailPWD__ '服務器上有效的密碼
obj.Priority = 1
obj.Host = EmailSMTP__
obj.Port = 25 ' 該項可選.端口25是默認值
obj.From = EmailFrom__
obj.FromName = EmailFormName__ ' 該項可選
obj.AddAddress ToEmail__'需要以,分開
obj.Subject = Subject__
obj.Body = MailBody__
if AttachFile__<>"" then obj.AddAttachment AttachFile__
obj.Send
If err then AspEmail=false
End Function
'=====================================================================================================
'使用Persits.MailSender發送郵件,發送成功返回true,發送失敗返回false
'help link http://msdn.microsoft.com/en-us/library/ms872547(v=EXCHG.65).aspx
'參數說明:
'EmailFrom__: 發送郵件的郵箱
'EmailID__: 發送郵件的郵箱帳號
'EmailPWD__: 發送郵件的郵箱密碼
'EmailSMTP__: 發送郵件的SMTP SERVER
'EmailSMTPPROT__: 發送郵件使用的端口//default is 25, gmail smtp is 465 or 587 , gmail pop3 995
'EmailSSL__: 是否使用套接字傳送
'EmailCharset__: 字符集
'ToEmail__: 發送的郵件地址
'Subject__: 郵件主題
'MailBody__: 郵件內容
'AttachFile__: 郵件附件
'=====================================================================================================
Function CDO(EmailFrom__,EmailID__,EmailPWD__,EmailSMTP__,EmailSMTPPROT__,EmailSSL__,EmailCharset__,ToEmail__,Subject__,MailBody__,AttachFile__)
'On Error Resume Next
CDO=True
Const cdoSendUsingMethod="http://schemas.microsoft.com/cdo/configuration/sendusing"
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 cdoSendUserName="http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword="http://schemas.microsoft.com/cdo/configuration/sendpassword"
Const cdoSendSmtpUsessl="http://schemas.microsoft.com/cdo/configuration/smtpusessl"
Const cdoSendLanguageCode="http://schemas.microsoft.com/cdo/configuration/languagecode"
Const cdoSendUsingPort=2
Const cdoBasic=1
'//value=0 代表Anonymous驗證方式(不需要驗證)
'//value=1 代表Basic驗證方式(使用basic (clear-text) authentication.
'//The configuration sendusername/sendpassword or postusername/postpassword fields are used to specify credentials.)
'//Value=2 代表NTLM驗證方式(Secure Password Authentication in Microsoft Outlook Express)
Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = EmailSMTP__
.Item(cdoSMTPServerPort) = EmailSMTPPROT__
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = EmailID__
.Item(cdoSendPassword) = EmailPWD__
.Item(cdoSendSmtpUsessl) = EmailSSL__
.Update
End With
Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig
With objMessage
.BodyPart.Charset = EmailCharset__
.To = ToEmail__
.From = EmailFrom__
.Subject = Subject__
.HtmlBody = MailBody__
End With
If AttachFile__<>"" then objMessage.AddAttachment AttachFile__
objMessage.Send
If err then CDO=false
Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
End Function
%>
申明
非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!
博文欢迎转载,但请给出原文连接。