Basic Email Scripting Examples for Marketers

Anonymous
Not applicable

I started using some email scripts about a year ago when our support for Velocity scripting was pretty new. As has no doubt become obvious by now, I’m not the most technical of consultants. (That’s why John’s on this blog.) In teaching myself how to do this, all I had to go off of was the documentation on the developer site (here), the Apache documentation (here), and trial and error.

Sadly, published examples of working email scripts for Marketo are still few and far between. So, while I cannot explain much about Velocity from the technical side, I can share some very basic email scripts that even a marketer like me can use.

If you don’t know how to properly create an email script token, you should refer to the doc here.

Example 1: Properly Capitalizing First Name

#set ($fname = ${lead.FirstName})

#if($fname.equals(""))

Friend

#else

$display.capitalize($fname)

#end

Example 2: Displaying a Greeting Based on Gender (Portuguese)

#if ( ${lead.gender} == "F" )

Cara Sra. Dra.

#else

Caro Sr. Dr.

#end

Example 3: Displaying a Greeting Based on Gender (German)

#if ( ${lead.Salutation} == "Mr." || ${lead.Salutation} == "Mr" )

Herr

#elseif ( ${lead.Salutation} == "Mrs." || ${lead.Salutation} == "Mrs" || ${lead.Salutation} == "Ms." || ${lead.Salutation} =="Ms" || ${lead.Salutation} == "Miss" )

Frau

#else

Herr

#end

Example 4: Displaying a Table with One Row for Each Sales Order for that Contact

<table border="1">

<tr>

<th>Item <th>Order ID</th><th>Date</th><th>Price</th>

</tr>

#foreach ( $SalesOrder in $SalesOrderList )

<tr>

<td>

$SalesOrder.Sales_Order_Item

</td>

<td>

$SalesOrder.Sales_Order_ID

</td>

<td>

$SalesOrder.Sales_Order_Date

</td>

<td>

$SalesOrder.Sales_Order_Price

</td>

#end

Example 5: Displaying Different Email Text in an Email Based on a Lead Field Value

#if(${lead.fieldname} == "fieldvalue1")

Email text here

#elseif (${lead.fieldname} == "fieldvalue2")

Email text here

#else

Email text here

#end

5219
9
9 Comments
Anonymous
Not applicable

We have done some amazing things in our emails using Velocity scripting and made our emails personalized and dynamic. Our biggest weekly batch blast (600+K) is very dynamic and it's all thanks to Velocity scripting.

As you mentioned, I learnt via trial & error to get it to work, had to sort of work around Marketo and in the end it was a wonderful feeling to see it all come together. We did learn some lessons hard way but in the end it was all worth it to the extent that we were chosen to present in 2015 Marketo Summit .

Link to our presentation (it includes some tech implementation screenshots as well) - Personalized Emails that Rock.

We have seen tremendous success of this email + ROI is amazing!! Since this, we have rolled out many similar Velocity script based emails (Trigger & Batch) and have had extremely great engagement. Couple of Marketo Customers also got in touch with us to learn how we have done this email, which was a great honor and testament of our work.

We would be happy to help if anyone wants to take their emails to next level.

Thanks,

Maruti.

Anonymous
Not applicable

Just learning how to write these scripts for the first time and I'm testing your First Name script. However, the script is adding a space after the first name. Any idea on how to fix this?

Anonymous
Not applicable

Can you post your velocity code? Also is the data corrupt i.e. the First Name is stored with extra space?

Can you try using HTML trim() method to eliminate the extra space?

JD_Nelson
Level 10 - Community Advisor

here's my header (I copied it from a template, so I'm not even sure what velocity scripting is)

<!DOCTYPE html>

<html lang="en">

<head>

<title>Spigit</title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<style type="text/css">

    /* RESET STYLES */

    body{margin:0; padding:0;}

    img{border:0; height:auto; line-height:100%; outline:none; text-decoration:none;}

    table{border-collapse:collapse !important;}

    body{height:100% !important; margin:0; padding:0; width:100% !important;}

    /* iOS BLUE LINKS */

    .appleBody a {color:#68440a; text-decoration: none;}

    .appleFooter a {color:#999999; text-decoration: none;}

    /* MOBILE STYLES */

    @media screen and (max-width: 625px) {

        /* ALLOWS FOR FLUID TABLES */

        table[class="wrapper"]{

          width:100% !important;

        }

        /* ADJUSTS LAYOUT OF LOGO IMAGE */

        td[class="logo"]{

          text-align: left;

          padding: 20px 0 20px 0 !important;

        }

        td[class="logo"] img{

          margin:0 auto!important;

        }

        /* USE THESE CLASSES TO HIDE CONTENT ON MOBILE */

        td[class="mobile-hide"]{

          display:none;}

        img[class="mobile-hide"]{

          display: none !important;

        }

        img[class="img-max"]{

          max-width: 100% !important;

          width: 100% !important;

          height:auto !important;

        }

        /* FULL-WIDTH TABLES */

        table[class="responsive-table"]{

          width:100%!important;

        }

        /* UTILITY CLASSES FOR ADJUSTING PADDING ON MOBILE */

        td[class="padding"]{

          padding: 10px 5% 15px 5% !important;

        }

        td[class="padding-copy"]{

          padding: 10px 5% 10px 5% !important;

          text-align: center;

        }

        td[class="padding-meta"]{

          padding: 30px 5% 0px 5% !important;

          text-align: center;

        }

        td[class="no-pad"]{

          padding: 0 0 20px 0 !important;

        }

        td[class="no-padding"]{

          padding: 0 !important;

        }

        td[class="section-padding"]{

          padding: 50px 15px 50px 15px !important;

        }

        td[class="section-padding-bottom-image"]{

          padding: 50px 15px 0 15px !important;

        }

        /* ADJUST BUTTONS ON MOBILE */

        td[class="mobile-wrapper"]{

            padding: 10px 5% 15px 5% !important;

        }

        table[class="mobile-button-container"]{

            margin:0 auto;

            width:100% !important;

        }

        a[class="mobile-button"]{

            width:80% !important;

            padding: 15px !important;

            border: 0 !important;

            font-size: 16px !important;

        }

    }

</style>

</head>

Anonymous
Not applicable

I don't see any velocity script in this HTML code.

Typically, velocity script would be embedded within the Email scripting token under the "My Tokens" tab. Then this token would be called within the email.

Hope this helps!

Maruti.

JD_Nelson
Level 10 - Community Advisor

thanks - turns out there was both a glitch and a typo -- in that I had a token in a token... what a bonehead move. That then caused velocity errors even when resolved.. but after I fixed it and created a new sample it worked.  Thanks though!

Nicol_Maurer
Level 3

I also tested example one, (as I am currently trying to split a first name and last name to first name only) to try and get an idea of how these work. I copied it just as it was above, but sadly mine returned no value at all.

Anonymous
Not applicable

Hi Maruti

I was wondering if you could help us with this. We would like to use the Velocity scripting and your advice would be much appreciated! What is the best way to start? Thank you very much!

Best wishes

Mon

SanfordWhiteman
Level 10 - Community Moderator

This post is years old (and has some questionable  code). Better to ask about specific objectives in new posts in Products.

You might start by searching my Nation posts for the word "Velocity" and also @ http://blog.teknkl.com/tag/velocity .