Due to low usage, this setting has been deprecated and has been removed. Click here for more information.
Section tags allow you to substitute in content in an SMTP message. Section tags are similar to substitution tags but are specific to the message, and not the recipient. You have to have a substitution tag value for each recipient, but you can have any number of section tags. Section tags can then contain Substitution tags for the recipient if needed. Section tags have to be contained within a Substitution tag since SendGrid needs to know which data to populate for the recipient. See the Section Tag Example Walkthrough below.
It's possible and acceptable to use only Substitution tags. However, that method is not DRY, and you may come against message size limitations.
When passing section
please make sure to only use strings as shown in our examples. Any other type could result in unintended behavior.
The format of the SMTP API section tag has the form:
1{2"section": {3":sectionName1": "section 1 text",4":sectionName2": "section 2 text"5}6}
How you flag your section tags may depend on the library you use to create your SMTP connection, the language you are writing your code in, or any intermediate mail servers that your servers will send mail through. In some cases -subVal-
may be the best choice while in other cases, %subVal%
, #subVal#
, or :subVal
may make more sense. The flag doesn't matter, as long as it's a unique string.
Do not use spaces inside your section or substitution tags! For example: %first name%
. The space breaks the string.
Do not nest section tags in sections! This causes your section to not be replaced.
Message body sent to SendGrid:
1<html>2<body>3Hi :salutation,<br />4Thanks so much for joining us at our event!56<p>7You have registered for the following event:<br />8:event_details.9</p>1011Thanks,<br />12The SendGrid Team13</body>14</html>
The accompanying X-SMTPAPI JSON header would look like:
1{2"to": [3"example1@example.com",4"example2@example.com",5"example3@example.com"6],7"sub": {8":salutation": [":female", ":male", ":neutral"],9":name": ["Alice", "Bob", "Casey"],10":event_details": [":event1", ":event2", ":event1"],11":event_date": ["Jan 1", "Feb 14", "Aug 11"]12},13"section": {14":male": "Mr. :name",15":female": "Ms. :name",16":neutral": ":name",17":event1": "New User Event on :event_date",18":event2": "Veteran User Appreciation on :event_date"19}20}
Alice receives:
1<html>2<body>3Hi Ms. Alice,<br />4Thanks so much for joining us at our event!56<p>7You have registered for the following event:<br />8New User Event on Jan 1.9</p>1011Thanks,<br />12The SendGrid Team13</body>14</html>
Bob receives:
1<html>2<body>3Hi Mr. Bob,<br />4Thanks so much for joining us at our event!56<p>7You have registered for the following event:<br />8Veteran User Appreciation on Feb 14.9</p>1011Thanks,<br />12The SendGrid Team13</body>14</html>
Casey receives:
1<html>2<body>3Hi Casey,<br />4Thanks so much for joining us at our event!56<p>7You have registered for the following event:<br />8New User Event on Aug 11.9</p>1011Thanks,<br />12The SendGrid Team13</body>14</html>