Use the Code Editor
Twilio SendGrid provides a marketer-friendly HTML Code Editor. This Code Editor features a split-screen editing experience for email messages with custom HTML and other features common in full-featured code editors.
To use the Code Editor, log in to the Twilio SendGrid console.
Decide what you want to create: a Single Send or an Automation message.
For Single Sends, you can choose one of three design options:
- A blank template
- A custom template that you have already created
- A pre-built template from Twilio SendGrid
To use the Code Editor for Single Sends:
- Go to Marketing > Single Sends.
- Decide if you want to create a message or edit an existing message.
- Click Create a Single Send. The Select a Design page appears.
- Choose from either Your Email Designs or SendGrid Email Designs.
As you hover over each design, text appears under the design indicating which editor, if any, someone used to create the design. You can choose a different editor, but Twilio recommends the editor displayed. - Hover over your chosen template and click Select. The Select Your Editing Experience page appears.
- Click Select in the Code Editor box. The Code Editor page appears with a banner that states Success! You've added a new single send.
To learn more, see Marketing Campaigns email designs.
Warning
Once you create a Single Send or automation email in the Code Editor, you can't edit with the Design Editor unless you add our Drag and Drop Markup.
When you add HTML code, you can write from scratch or use code from another HTML editor. To use HTML code from another application, copy and paste that code into the content area of the Code Editor.
When you write your HTML code, consider the following examples. They show the recommended structure and organization of custom HTML code. Twilio represents the content of your modules as [MODULE CONTENT].
Twilio SendGrid doesn't lint or otherwise validate your HTML code outside of flagging errors.
1<table class="module" role="module" data-type="text">2<tr>3<td style="[CSS rules]; background-color: [some color]">4[MODULE CONTENT]5</td>6</tr>7</table>
You can review your email message or template in a preview.
- To preview your email message or template, click Preview.
- To view the desktop preview, click Desktop.
- To view the mobile preview, click Mobile.
- To view a plain-text version of your email message or template, click Plain Text.
Previews also display your chosen From name, Subject, and Preheader text.
-
If you went away from the Code Editor, go to Marketing > Single Sends or Automations page.
-
Click on your desired email message. The Code page for that email message appears.
-
Select the images icon atop the HTML code. The Image Library appears.
-
Click the image you want to add to your email. The Image Details panel appears.
-
Click Copy Image URL. The Image URL Copied banner appears.
-
Close the Image Library page.
-
In your email message or template HTML code, paste this URL into an
imgsource tag.<img src="hostname/path/to/image.ext" />
Twilio SendGrid provides personalization of email messages. To accomplish this, you add substitution tags to your email messages or templates and provide test data to validate the tags.
To view a preview with the integrated test data:
-
Open a design in the Design Editor.
-
Click Preview.
-
Click Show Test Data. The test data panel appears.
-
Insert contact data into the code window.
- The data uses JavaScript Object Notation (JSON) syntax.
- JSON structures data as a collection of key-value pairs.
(information)Example of a test data JSON
If you use the
first_namesubstitution tag, the key isfirst_nameand the value is the customer's name. Think of these keys as variables. Like a variable in algebra, these variables represent a value you don't yet know.1{2"first_name": "Tira",3"last_name": "Misu",4"email": "recipient@example.com",5"alternate_emails": "recipient+@example.com",6"address_line_1": "1234 N. Real Ave.",7"address_line_2": "Suite 200",8"city": "Denver",9"state_province_region": "CO",10"postal_code": 80202,11"country": "United States",12"phone_number": "+15555555555",13"Sender_Name": "Orders",14"Sender_Email": "orders@example2.com",15"Sender_Address": "1234 N. Exist St.",16"Sender_City": "Portland",17"Sender_State": "OR",18"Sender_Zip": 97227,19"Sender_Country": "United States"20} -
After you save the test data, any substitution tags should display the data in the email preview.
To add categories:
- Click the Settings drawer. The Settings panel appears.
- Expand the Single Send Settings menu.
- In the Categories box, add categories in one of two ways:
- Click in the Categories box and choose a category from the dropdown menu.
- Click in the Categories box and type the name of a category you want to add.
- If the category exists, it displays once you type enough characters in its name.
- If it doesn't exist, it prompts you to add a category with that name.
Every email message includes machine-readable information like its title and what styles get applied to its content. With the editor, you can add this information, or metadata, to your email messages.
The HTML [<head>][] element contain any metadata you want in your email message or template.
To define any custom fonts or CSS styles, you can use the <head> element.
To edit the HTML head of your email message or template:
- Click the Settings drawer. The Settings panel appears.
- Click Build. The Build panel appears.
- Expand the Advanced menu.
- Click the Edit next to Edit HTML Head. The Edit HTML Head appears.
<head></head>
- Make your desired changes.
- Click Update.
Using the tag to reference a web font hosted on the internet, users add custom fonts like [Google Fonts][]. Define a web-safe font as a fallback should one of your recipient's clients not support your custom font.
The following popular clients support web fonts:
- Apple Mail
- Outlook.com app
- Outlook 2000
- Default Android Mail app (not the Android Gmail app)
- iOS Mail
This list might change. Twilio can't guarantee web font support. Some inbox providers don't support fonts.
To add a custom font using the HTML <head>:
-
Open the HTML Head by navigating to the Build tab in the Design Editor.
-
Scroll down to the Advanced drop-down menu and select Edit HTML Head.
-
Click Edit to begin making your changes.
-
Insert a
<link>tag containing anhrefattribute that points to your web font.<link href="https://fonts.google.com/specimen/Oswald" rel="stylesheet" /> -
To indicate that you want to use the web font, add an HTML
<style>tag with CSS rules:1<style>2body { font-family: 'Oswald', sans-serif; }3</style>
Twilio SendGrid hosts the images included in the pre-built templates and any images you have uploaded to the image library, so when you export a template's HTML from the design editor, the embedded URLs in each <img> tag remains valid.
To open exported HTML in the Code Editor using Single Sends:
- Go to Marketing > Single Sends.
- Click Create a Single Send. The Select a Design page appears.
- Click Your Email Designs.
- Hover over Blank Template and click Select. The Select Your Editing Experience page appears.
- Click Code Editor.
- Paste the raw template HTML into the Code Editor.