Forum Moderators: open

Message Too Old, No Replies

Generating a validation link in mail for subscription

validation link mail

         

Unders_On

2:28 am on Jul 9, 2003 (gmt 0)

10+ Year Member



Hi everybody!
I`m developing a site that requires subscription in which I would like to generate random links after a button was pressed to send an e-mail back to the subscription candidates mail, as a way to validate their mail address .And also, by clicking there, they should be redirected to the site login page, something similar to what happens when we join this forum . The site is being developed in ASP . If anyone could sent me some piece of ASP code that could perform that, I would appreciate it . Thank you in advance,

Unders On/Rio de Janeiro/Brazil

WebJoe

6:02 am on Jul 9, 2003 (gmt 0)

10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com] Unders_On

To accomplish what you mentioned you need the folowwing:

1. A webpage with a form:


[...]
<FORM NAME="Subscribe" METHOD="post" ACTION="subscription.asp">
<LABEL FOR="Name">Name:</LABEL><INPUT TYPE="text" NAME="tbsName" SIZE="20" ID="Name" TABINDEX="2">
<LABEL FOR="Email">Email:</LABEL><INPUT TYPE="text" NAME="tbsEmail" SIZE="20" ID="Email" TABINDEX="5">
<INPUT NAME="tbsCc" TYPE="hidden" ID="mail_cc" VALUE="">
<INPUT NAME="tbsBcc" TYPE="hidden" ID="mail_bcc" VALUE="unders_on@somedomain.tld">
<INPUT NAME="tbsSubject" TYPE="hidden" ID="mail_subject" VALUE="Confirmation mail">
<INPUT NAME="tbnImportance" TYPE="hidden" ID="mail_importance" VALUE="1">
<INPUT NAME="tbsAnswerfile" TYPE="hidden" ID="mail_redirect" VALUE="confirmation.asp">
<INPUT TYPE="submit" VALUE="Subscribe">
</FORM>

2. The script that processes the users input (subscription.asp, in this case in the same folder as the form):


<%
'* **********************************************************************
'* MODULE : subscription.asp
'* AUTHOR : WebJoe
'* CREATED : Dec 11 2002
'* COMPATIBILITY : MS WinNT 4.0 Server, IIS4 w/ Option Pack 4 & simple SMTP
'* DESCRIPTION : Sends mail with text from a form
'* The following fields are mandatory in the form:
'* tbsEmail, tbsCc, tbsBcc, tbsSubject,
'* tbnImportance, tbsAnswerfile.
'* DISTRIBUTION : Freely redistributable. Use at your own risk.
'* **********************************************************************

Dim lsFrmField, lsMsgBody
Dim lsFrmFrom, lsFrmTo, lsFrmCc, lsFrmBcc, lsFrmSubject, lsFrmImportance, lsFrmRedirect
Dim loCDOMail

'-------------------------------------------------------
' Get values from hidden fields for sending the mail
'-------------------------------------------------------

lsFrmFrom = Request.Form("tbsEmail")
lsFrmCc = Request.Form("tbsCc")
lsFrmBcc = Request.Form("tbsBcc")
lsFrmSubject = Request.Form("tbsSubject")
lsFrmImportance = Request.Form("tbnImportance")
lsFrmRedirect = Request.Form("tbsAnswerfile")

'-------------------------------------------------------
' Evaluate recipient
'-------------------------------------------------------

lsFrmTo = lsFrmFrom

'-------------------------------------------------------
' If values are empty, put in some defaults
'-------------------------------------------------------

If lsFrmFrom = "" Then
lsFrmFrom = "Unders ON <unders_on@somedomain.tld>"
End If

If lsFrmCc = "" Then
lsFrmCc = lsFrmCc
End If

If lsFrmBcc = "" Then
lsFrmBcc = "unders_on@somedomain.tld"
End If

If lsFrmSubject = "" Then
lsFrmSubject = "Confirmation mail"
End If

If lsFrmImportance = "" Then
lsFrmImportance = 1 ' 0: low, 1: normal, 2: high
End If

If lsFrmRedirect = "" Then
lsFrmRedirect = ""
End If

'-------------------------------------------------------
'Get all form elements and structure the e-mail
'-------------------------------------------------------

For Each lsFrmField In Request.Form
Select Case lsFrmField
Case "tbsEmail", "tbsCc", "tbsBcc", "tbsSubject", "tbnImportance", "tbsAnswerfile"
lsMsgBody = lsMsgBody
Case Else
lsMsgBody = lsMsgBody & Mid(lsFrmField, 4, Len(lsFrmField)-3) & _
Space(25-Len(lsFrmField)) & ": " & Request.Form(lsFrmField) & vbCrLf
End Select
Next

lsMsgBody = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbCrLf & _
lsFrmSubject & vbCrLf & _
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbCrLf & vbCrLf & _
lsMsgBody & vbCrLf & _
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbCrLf & vbCrLf & _
"Script Provided by WebJoe" & vbCrLf

'-------------------------------------------------------
'Get values from hidden fields for sending the mail
'-------------------------------------------------------

Set loCDOMail = Server.CreateObject("CDONTS.NewMail")

loCDOMail.BodyFormat = 1
loCDOMail.MailFormat = 1
loCDOMail.From = lsFrmFrom
loCDOMail.To = lsFrmTo
loCDOMail.CC = lsFrmCc
loCDOMail.BCC = lsFrmBcc
loCDOMail.Subject = lsFrmSubject
loCDOMail.Importance = lsFrmImportance
loCDOMail.Body = lsMsgBody

'--------------------------------------------------
'Sending the text and error handling
'--------------------------------------------------

loCDOMail.Send

If Err.Number = 0 Then ' OK?
If lsFrmRedirect = "" Then
Response.Write "<P>Thank's for your input.<BR><A HREF=""/"">Go back to start.</A></P>"
Else
Response.Redirect(lsFrmRedirect)
End If
Else ' Not OK!
Response.Write "<P>An error has occured. Please " _
& "contact your sysadm." _
& "Error: " & objSend.Response & "</P>"
End If

Set loCDOMail = Nothing

%>

3. A server running IIS with option pack 4 (for CDONTS) and SMTP running.

For other solutions (there are many mailing options for asp) check with asp-sites as 4guysfromrolla, freevbcode, aspin etc.

Unders_On

1:49 pm on Jul 9, 2003 (gmt 0)

10+ Year Member



Thanks Web Joe!
I`m going to be trying to follow your example`s steps in order to accomplish what I intend to, and certainly I am deeply pleased to hear from you . Hope to be successful, once more thank you very much .


Unders On/Rio de Janeiro/Brazil

WebJoe

10:19 pm on Jul 9, 2003 (gmt 0)

10+ Year Member



Unders_on, I'm glad to have been of help. If you have any troubles implementing it just come back here.