The last feature to implement is the editing and sending of messages. This part of the functionality is provided by the email_list.asp file, and its interface is shown in Figure 6. Next we'll analyze the file.
Email_list.asp's internal work process is similar to Edit_record.asp's. The administrator writes the message in the form and submits it, and the system selects all records with the Mail_list field value "Yes" and sends a copy of the new message to the Guest_mail address in those records.
Every time we send a message, we re-create the mailer object and close it after the send is complete. This is important because we need to modify the body of the message and add the URL and ID number of the UNSUBSCRIBE mailing list.
If Request.ServerVariables ("request_method") = "POST" Then
Strsubject = Request.Form ("Txtsubject")
Strbody = Request.Form ("Txtbody")
Strfrom = Request.Form ("Txtfrom")
' Select Recipient records from the database
Strsql_selectemail = "Select guests.guest_id, Guests.guest_email" & _
"From Guests WHERE ((guests.mail_list) =-1);"
Set oconn = Server.CreateObject ("ADODB. Connection ")
oConn.Open Strdsnpath
Set Rsmail = Oconn.execute (strsql_selectemail)
If Rsmail.bof = True and rsmail.eof = True Then
... Database is empty prompt, slightly ...
Else
Rsmail.movefirst
Do as not rsmail.eof
' Create object
Set Mailer = Server.CreateObject ("Smtpsvg.mailer")
' Fill in other message header information
Mailer.fromname = Strfrom
Mailer.fromaddress = Stremailfrom
Mailer.remotehost = Strhost
Mailer.subject = Strsubject
Mailer.bodytext = ... Set the content of the message, slightly ...
Strto = Rsmail.fields ("Guest_email"). Value
If Strto < > "" Then
Mailer.recipient = Strto
If Mailer.sendmail Then
... Send success prompt, slightly ...
Else
... Send failure prompt, slightly ...
End If ' Mailer.sendmail
End If ' Strto < > ' "
Rsmail.movenext
Set Mailer = Nothing
Loop
End If ' Rsmail.bof = True and rsmail.eof = True
Rsmail.close
Set Rsmail = Nothing
Oconn.close
Set oconn = Nothing
End If ' Request_method = ' POST '
It should be noted here that we assign the value of the variable Strhost to the RemoteHost property of the Aspmail instance object. Therefore, you must ensure that the value of Strhost is a suitable mail server name (such as mail.mydomain.com).
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.