I am using AWS SES to send emails by following the doc https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-personalized-email-api.html. The HTML part in the sample template is too short, but I need a long HTML part with multiple lines. For example, it has several lines as the following:
{
"Template": {
"TemplateName": "Group_Invitation",
"SubjectPart": "{{who}} has invited you to join team {{group_name}}",
"TextPart": "",
"HtmlPart": ["<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>{{name}}</body>
</html>"]
}
}
I cannot upload this template. It will show errors
Error parsing parameter 'cli-input-json': Invalid JSON: Invalid control character at: line 6 column 32 (char 182)
JSON received: {
"Template": {
"TemplateName": "Group_Invitation",
"SubjectPart": "{{who}} has invited you to join team {{group_name}}",
"TextPart": "",
"HtmlPart": ["<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>{{name}}</body>
</html>"]
}
}
I am not sure how I can handle the htmlpart with multiple lines.
The data you are sending should be preformatted to be a valid JSON file. To make sure it is valid you need to escape some special charaters:
Newline
escaped as \n
Carriage return escaped \r
There are some online tools that you can use to validate your JSON. One of them is jsonlint.com
Also take note that new lines in HTML are expressed as <br />
not as literal new line in a file.
Your JSON file should be formatted as following:
{
"Template":{
"TemplateName": "Group_Invitation",
"SubjectPart": "{{who}} has invited you to join team {{group_name}}",
"TextPart": "",
"HtmlPart": "<!doctype html><html><head><meta charset=\"utf-8\"></head><body>{{name}}<br />some text on the other line</body></html>"
}
}
Also you can use JSON Escape/ Unescape tool, and paste your HtmlPart, to quickly replace all the new lines and have it valid for sending via JSON.
Escaped HtmlPart
<!doctype html>\r\n <html>\r\n <head>\r\n <meta charset=\"utf-8\">\r\n <\/head>\r\n <body>{{name}}<\/body>\r\n <\/html>
You now can take this string, quote it and use it as HtmlPart. As you can see this tool escapes forward slashes as well but it is not required as stated in this answer