The current project requires regular email delivery using Asp, and many people say that Asp does not have such a function.
Actually, I have explained it in detail in a previous article, but that is a timed task, and the basic idea is the same.
Reference: Methods for implementing timing tasks in ASP
Here we use the JMail component to do it. The content of the email is a single web page and can be customized freely.
Let's take a look at the code for sending timed mail:
The code copy is as follows:
Function getHTTPPage(url)
dim objXML
set objXML=createobject("MSXML2.SERVERXMLHTTP.3.0") 'Call the XMLHTTP component to test whether the space supports XMLHTTP
objXML.open "GET",url,false 'false means to get web code in a synchronous way, understand what synchronization is? What is asynchronous?
objXML.send() 'Send
getHTTPPage=bBytesToBstr(objXML.responseBody)' returns information, and use function to define encoding.
set objXML=nothing'Close
End Function
Function bBytesToBstr(body)
dim objstream
set objstream = CreateObject("adodb.stream") '//Calling the adodb.stream component
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = "GB2312"
'Convert the original default UTF-8 encoding to GB2312 encoding, otherwise you will get garbled code by directly calling a web page with Chinese characters with XMLHTTP.
bBytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
end Function
Sub SendAction(subject, mailaddress, Tomail, sender, content, fromEmail, Fromer, UserName, PassWord)
Set oJmail=CreateObject("Jmail.Message")
oJmail.Logging=false
oJmail.Silent=True
oJMail.Priority = 3
oJmail.FromName=Fromer
oJmail.From= FromEmail
oJmail.CharSet="gb2312"
oJmail.MailServerUserName = UserName
oJmail.MailServerPassWord = PassWord
oJmail.ContentTransferEncoding = "base64"
oJMail.HTMLBody = content 'Mail content
oJMail.Body =content'"Our emails are in HTML format, but your email viewing software may not support them"
oJmail.AddRecipient Tomail 'Recipient Address
oJmail.Subject = subject 'Title
oJmail.Send(mailaddress)
End Sub
dim Subject, MailAddress, ToEmail, Sender, FromEmail, Fromer, PassWord, oJmail, usernames, tomail