programming

You are currently browsing the archive for the programming category.

I’m about to start the fourth week at my new job. I’m the new director of web technology at Targetbase, a marketing agency. While my last job was also at a marketing agency this new place is very different. For one thing it’s bigger and the average employee age is much older. I’m surrounded by very experienced people and so occasionally I feel like the dumbest guy in the room. But I know that’ll pass as I get more comfortable.

My immediate task is to build the capabilities of the group so that we can begin handling more website projects in house. That shouldn’t be too hard. I inherited two excellent developers who are hungry to do some challenging work. So look out!

Tags: ,

For a long time we’ve been Bookpool.com customers, but recently we discovered that a competing online tech book seller is a resident in our neighborhood! Nerdbooks.com has pictures of the warehouse on their web site and at one point had an invitation for people to stop by. The web site doesn’t say that anymore so this morning I called them up to see if they still welcome visitors.

Friendly Dave told me that yes, you are welcomed at any time as long as you agree to three conditions … 1) you’re not scared of dogs. They have some beautiful resident Labradors running around inside the warehouse. 2) you shut the door behind you. The Labs are fond of romping around parking lot. 3) Don’t bring small children. Their warehouse consists of aisles and aisles of books arranged in very logical groupings with comfy couches and chairs to sit at and three Macintosh computers to shop with.

It’s not a store in the traditional sense. It is truly their warehouse. But you’re welcome to browse all you want. When you find something you want to buy you use one of the Macs to make your purchase through the web site (no shipping charges). The Mac automatically prints out your order in their office. Within a minute someone came over to doublecheck that we had the books we purchased.

What an incredibly relaxing shopping experience. I could spend hours there!

Here’s what we picked up:

Tags:

A lot of the sites we build include email functionality … send-to-a-friend, invites, confirmation emails, admin error notices, etc. Here’s one way to do it.

First you need to have an HTML email. Rather than putting this in my code-behind I keep it as a separate file so if someone wants to update it later on they just have to deal with the HTML … and there are always changes. The HTML will include tokens for the instances where we want to insert items, like names, email addresses, hyperlinks, etc. Like so …

<p>Hello [FIRSTNAME],</p>
<p>Thank you for registering at [WEBSITENAME]!</p>

Then in our code-behind I create a StringBuilder object and read in the HTML file using a StreamReader. I use a StringBuilder over just a String because I can call helper methods like StringBuilder.Replace() and it works on the existing object. With String I would have to create a new instance to hold the results of the Replace(). So I do a replace for each time I want to replace a token in the HTML with some text. In this example I’m replacing [FIRSTNAME] with the email recipient’s first name and [WEBSITENAME] with the name of the website the user just registered at.

Dim oStrRdr As System.IO.StreamReader
Dim docPath as String = Server.MapPath("email.html")
Dim contents As New StringBuilder

If System.IO.File.Exists(docPath) Then

    oStrRdr = System.IO.File.OpenText(docPath)
    contents.Append(oStrRdr.ReadToEnd)
    oStrRdr.Close()

End If

contents.Replace("[FIRSTNAME]", "Jason")
contents.Replace("[WEBSITENAME]", "ChetWeb.com")

Now I just need to send my email (assuming that the SMTP server we’re using is named in the web.config file in a key called “smtpserver”.

Dim mm As New System.Net.Mail.MailMessage("sender@somedomain.com","recipient@gmail.com","Welcome to my world!",contents.ToString)

mm.IsBodyHtml = True
mm.BodyEncoding = System.Text.Encoding.UTF8

Dim smtp As New System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings("smtpserver").ToString)

smtp.Send(mm)

One important setting that you need to make is “IsBodyHtml=True”. This tells the MailMessage object that the email is an HTML email. The other setting “BodyEncoding=’utf-8′” is especially important when you’re sending non-Latin based language emails, like Japanese. If you don’t specify the character encoding used for the body your recipient could receive gibberish.