XMLHttpRequest Undefined

I am having below script inside workflow. However, the below error was returned:
[0002] W3602 : Error 0 on line 23, column 1: Microsoft JScript runtime error: ‘XMLHttpRequest’ is undefined
Please advise

/----Sending fully featured email----/

function createFormData(data) {
var formData = new FormData();
for (var key in data) {
formData.append(key, data[key]);
}
return formData;
}

//Dummy File Object
var file = new File([“”], “filename”);

var data = {
‘from’: ‘Sender Name from@example.com’,
‘to’: ‘recipient1@example.com’,
‘subject’: ‘Test Subject’,
‘html’: ‘HTML Body’,
‘text’: ‘Sample Email Body’,
‘attachment’: file,
‘intermediateReport’: ‘true’,
‘notifyUrl’: ‘https://www.example.com/email/advanced
};

var xhr = new XMLHttpRequest();
xhr.withCredentials = false;

xhr.addEventListener(‘readystatechange’, function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});

xhr.open(‘POST’, ‘https://{base_url}/email/2/send’, false);
xhr.setRequestHeader(‘authorization’, ‘Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==’);
xhr.setRequestHeader(‘accept’, ‘application/json’);

xhr.send(createFormData(data));

You need an ActiveXObject in Workflow Scripts.

There is a good how-to for that: Scripts: Communicate with an HTTP(S) API from Workflow - OL® Learn