I am using code (see below) that I found for sending an AWS SES message with an HttpRequest to amazon. I am able to send MIME messages with PDF attachments and all has been great.
Today, I tried changing from text/plain (in my body) to text/html, and added div tags, so that I could add some formatting to the emails.
Unfortunately, somewhere along the way, the '>' character in the tags is getting converted to '?', which breaks the html. This only happens to about one in three instances and I cannot tell what factor determines whether the '>' remains as '>' or shows up in the email as '?'.
I have taken the base 64 encoded value from this line and run it through web based decoding tools, and it appears to be fine:
EncodingUtil.base64Encode(Blob.valueOf(body)).replaceAll('=','%3D')
Are there any known complications with HttpRequest posts that might be responsible for breaking the html tags?
String emailRequest = 'Action=SendRawEmail';
emailRequest += '&RawMessage.Data=' + EncodingUtil.base64Encode(Blob.valueOf(body)).replaceAll('=','%3D');
AWSHelper helper = new AWSHelper('us-east-1','ses');
helper.sendEmail(Blob.valueOf(emailRequest));
private String httpMethod = 'POST';
public void sendEmail(Blob mimeMessage) {
Map<String,String> queryParams = new Map<String,String>();
Map<String,String> headerParams = new Map<String,String>();
headerParams.put('content-type','application/x-www-form-urlencoded');
headerParams.put('content-length', String.valueOf(mimeMessage.size()));
headerParams.put('date',requestTime.formatGMT('YYYYMMdd\'T\'HHmmss\'Z\''));
headerParams.put('host',new URL(awsSESEndPoint).getHost());
HttpRequest request = new HttpRequest();
request.setMethod(httpMethod);
request.setBodyAsBlob(mimeMessage);
request.setEndpoint(awsSESEndPoint);
for(String key: headerParams.keySet()) {
request.setHeader(key, headerParams.get(key));
}
request.setHeader('Authorization',authorizationHeader(mimeMessage,queryParams,headerParams));
HttpResponse response = new Http().send(request);
if(response.getStatusCode() == 200) {
ResidentCommonFns.addPageMessage('Successfully Sent Email','Confirm');
} else {
ResidentCommonFns.addErrorMessage(response.getBody());
}
}
.replaceAll('=','%3D')
should instead beEncodingUtil.urlEncode(... ,'utf-8')
However, I don't think this will fix your problem.