Today I am developing user messages. One copy is stored in the database, and the other copy needs to be sent to a specified mailbox. I don’t know if the server supports it. If it supports it, the message information will be sent to email. First, there must be a statement On Error Resume Next
Then try resume jmail example:
Dim JMail
Set JMail=Server.CreateObject(JMail.Message)
Make a judgment on the instance. If the component is not installed successfully, no instance is created:
If JMail Is Nothing Then
Response.Write is not supported
Else
Response.Write support
End If
The other components are processed in the same way, which is very simple.
It's best to handle it in the global file, so you don't have to worry about it when using it.
The best way is to put the email generation in a table and then talk about sending it.
Copy the code code as follows:
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err = 0
DimxTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End Function
Judgment code:
if IsObjInstalled(JMail.Message)=True then{
if IsObjInstalled(JMail.Message) =True then
SendStat = Jmail(***@vevb.com, customer message from the Internet, <html><head><meta http-equiv=Content-Type content=text/html; charset=gb2312><title>Website user message</title></head><body>Message person: &txtname&<br>Gender: &xingbie&<br>Consulting website: &txtweb&<br>Contact information: &txttel&<br>Message content :&cont ent&<br>IP address:&ipaddress&<br>Message time:&now()&<br><br>This email is automatically sent by the system, no reply is required<!--Script Home www.vevb.com--><br ><br></body></html>,GB2312,text/html)
end if
}
jmail sending function
Copy the code code as follows:
' ============================================
' jmail sends email
' ============================================
Function Jmail(mailTo,mailTopic,mailBody,mailCharset,mailContentType)
'Entry parameters:
' mailTo recipient email address
'mailTopic mail topic
' mailBody email body (content)
' mailCharset mail character set, such as GB2312 or US-ASCII
' mailContentType email body format, such as text/plain or text/html
'Return value:
' String, OK will be returned after successful transmission, error message will be returned if unsuccessful.
'Usage:
' 1) Set the constant, that is, the variable starting with Const
'2) Use code similar to the following to send a message
'Dim SendStat
'SendStat = Jmail([email protected], test Jmail, this is a test letter!, GB2312, text/html)
'Response.Write SendStat
'******************Set constants as needed to start******************
Dim ConstFromNameCn,ConstFromNameEn,ConstFrom,ConstMailDomain,ConstMailServerUserName,ConstMailServerPassword
ConstFromNameCn = Lottery Network's Chinese name of the sender (used when sending Chinese emails), such as 'Zhang San'
ConstFromNameEn = bc5'The English name of the sender (used when sending English emails), such as 'zhangsan'
ConstFrom = [email protected]' sender's email address, such as '[email protected]'
ConstMailDomain = smtp.163.com'smtp server address, such as smtp.163.com
ConstMailServerUserName = [email protected]'smtp server's mailbox login name, such as 'zhangsan'. Be sure to match the sender’s email address!
ConstMailServerPassword = www.vevb.com'smtp server's mailbox login password
'******************Set constants as needed to end****************
'--------------------------------The following content does not need to be changed---------------- ---------------
On Error Resume Next
Dim myJmail
Set myJmail = Server.CreateObject(JMail.Message)
myJmail.Logging = False'Logging
myJmail.ISOEncodeHeaders = False'Mail headers do not use ISO-8859-1 encoding
myJmail.ContentTransferEncoding = base64'Mail encoding is set to base64
myJmail.AddHeader Priority,3'Add mail header, do not change it!
myJmail.AddHeader MSMail-Priority,Normal'Add the mail header, do not change it!
myJmail.AddHeader Mailer,Microsoft Outlook Express 6.00.2800.1437'Add mail header, do not change it!
myJmail.AddHeader MimeOLE,Produced By Microsoft MimeOLE V6.00.2800.1441'Add mail header, do not change it!
myJmail.Charset = mailCharset
myJmail.ContentType = mailContentType
If UCase(mailCharset) = GB2312 Then
myJmail.FromName = ConstFromNameCn
Else
myJmail.FromName = ConstFromNameEn
End If
myJmail.From = ConstFrom
myJmail.Subject = mailTopic
myJmail.Body = mailBody
myJmail.AddRecipient mailTo
myJmail.MailDomain = ConstMailDomain
myJmail.MailServerUserName = ConstMailServerUserName
myJmail.MailServerPassword = ConstMailServerPassword
myJmail.Send ConstMailDomain
myJmail.Close
Set myJmail=nothing
If Err Then
Jmail=Err.Description
Err.Clear
Else
Jmail=OK
End If
On Error Goto 0
End Function