POTO - plain old text "object"

Legacy systems, don't you just love them. Occasions when you become more of a curator than a developer.

Here's one. A system handles requests by receiving plain text email, processing the body of the email according to some macros i guess. it is very strict, so even if you send a "plain text" email i.e. no markup, but the content type is not plain text, it refuses to process the email.

OK, we have a bunch of various forms that utilise SharePoint workflow and the email step to send the email to the system. A horrid messof server suide component was hosted on SharePoint, using some MOSS era codeplx components, that whilst worked, was certainly not in the app m,odel or teanabl for future cloud migration.

SO the seemingly simple idea of developing an SharePoint hosted add-in (FKA app) seemed a great way to bring all of this up to date adhering to the new principles of best practice development.

No REST for the wicked

SharePoint doesnt honour the additional headers in the JSON for the email

var url = _spPageContextInfo.siteAbsoluteUrl + urlTemplate;
var mail = {
    'properties': {
        '__metadata': { 'type': 'SP.Utilities.EmailProperties' },
        'From': TPR.Modules.Facilities.emailAddressFrom,
        'To': { 'results': [TPR.Modules.Facilities.emailAddressTo] },                      
        'CC': { 'results': [TPR.Modules.Facilities.emailAddressCc] },             
        'Body': TPR.Modules.Facilities.Message,
        'Subject': subject,
            '__metadata': {"type":"Collection(SP.KeyValue)"},
                '__metadata': {'type': 'SP.KeyValue' },
                'Key': 'Content-Type',
                              'Value': 'text/plain; charset=us-ascii',
                              'ValueType': 'Edm.String'

console.log('mail: ' + mail);
console.log('url:' + url);

var requestBody = JSON.stringify(mail);

/* this doesnt work, sending as plain text, so no use at the moment*/ $.ajax({ contentType: 'application/json;odata=verbose', url: url, method: "POST", data: requestBody, headers: { "X-RequestDigest": $("#__REQUESTDIGEST").val() }, success: function (data) { console.log("Mail sent"); console.log('url posted to: ' + urlTemplate);
}, error: function (data, errorCode, errorMessage) {
console.log('mail not sent:' + JSON.stringify(errorMessage));
} });