Free! A send-a-friend application with ASP Smart Mailer Support

The great thing with DMXzone's extensions is that they make the tedious work of developing advanced functions easy, allowing you to concentrate on the exciting aspects of the job.

In this free tutorial, Matt Machell shows how to use the DMXzone ASP Smart Mailer to add a "send-a-friend" link to your web pages, allowing a user to alert a friend to an interesting page by clicking a link, entering an email address and the DMXzone extension and your web server do the rest. It'll have you up and running this functionality on any page, on any number of sites, in practically no time at all!

Adding the Smart Mailer

So, with the basic page layout finished we move on to adding the behavior that actually does the mailing. In the Server Behaviors panel, click + > DMXZone > Smart Mailer. The dialog that pops up should look like this:


Smart Mailer's Main Tab

For the From fields we'll use the dynamic data lightning flash to add our previously created bindings: name and email. The To fields we'll use the fname and femail bindings. We'll set the when Send field to On Form Submit (this is the default) and make sure it submits when we use the sendafriend form.

That's all we need for that tab. Now move on to the Content tab.

Smart Mailer's Content Tab


In the subject box, we'll put "sent by a friend from yoursite.com", but you should insert whatever your own site is called here. To keep things simple we'll use the text content Type, although if you wanted to make it a snazzier email you could use the HTML option combined with the Advanced HTML Editor extension instead of a normal text area (read on for more details in sending HTML mails).

The body of our message is created in the Static text/HTML area. If you want to insert data from a dynamic source, use the lightning bolt icon. This will add the binding between ## marks at your current cursor position. For our message I used the following:

Your friend ##Request("name")## visited page: ##Request("url")##

They also left the following message:

##Request("message")##

This message sent via the sendafriend script at oursite.com. Report abuse of the script to: abuse@oursite.com . The sender's IP address was ##Request.ServerVariables("REMOTE_ADDR")##

Our email is made up of a variety of bits of dynamic data and plain text. We take the form values name and url and insert them into the basic text, then add the custom message from the user.

Finally we add a bit of security to protect people from abusive messages via our send-a-friend system. We give an email address for people to report abuse of the script to us, and log the IP address of the person who used the script. This is important if you allow a custom message, as people could literally write anything! If you're using a script like this on a commercial site, it's sensible to take legal advice on if you could be held liable for any use of the application.

Since we're not sending attachments, move on to the setup tab:


Smart Mailer's Set-up Tab

This tab gives you options for how your email is sent, since installations of ASP vary in what email services they provide. Path Type lets the extension know how to include the dependent file that actually runs the emailing procedure. You'll be okay with related, unless your server has parent directories disabled (you can't use ../).

The Component box is the most important as it tells the script which one is present on your server. If you're using a web hosting company, check with them which email service is provided. Typically, NT and older Windows 2000 hosting uses CDONTs (Collaboration Data Objects for Windows NT Server) and newer Windows 2000/2003/XP servers will use CDO (Collaboration Data Objects). Some providers use Jmail, ASPMail and ASPEmail, for whatever reasons.

Once you know which type of email service is installed, it's simply a matter of filling in the boxes correctly. For most this is just a case of adding in the mail server you wish to use (which will likely be something like mail.yoursite.com). Some will have a different name, others will be secure and require an email account username and password before they'll send anything. You'll also want to set up whether to ignore errors or report them to the user when sending mail. For this application I've set it to ignore.

The redirect URL tells our application where to forward the user to after mailing is complete. We're using sendafriendconfirm.asp. Using the file browser we'll also add two parameters to the url so that we can do some reporting. These are fname and url, which are the same as our Bindings.

With smart mailer added, we can close that page.

Matt Machell

Matt MachellA man of many talents, Matt has been a web designer, technical editor, and jewellery picker. He is currently on contract for the Birmingham City University, producing pages for research centres.

He has tech-edited a dozen books on web design and development for glasshaus, Apress and Sitepoint.

He likes music with loud guitars and games with obscure rules.

His website can be found at: http://www.eclecticdreams.com

He lives in Birmingham with his girlfriend, Frances, and a horde of spider plants.

See All Postings From Matt Machell >>