durs / node-activex

Node.JS Implementaion of ActiveXObject

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't Set the SendUsingAccount property when using the Outlook ActiveX

somanuell opened this issue · comments

Hi durs,
I have a test case where cscript.exe does the work, but winax fails.
When setting some property in some object, in node.exe the property is seen as null just after the affectation, but not in cscript.exe

Is there a syntax I should use to set the property's value?

Below, script for reference, the offending code is oMail.SendUsingAccount = oTheAccountToUse;

if ( typeof module !== 'undefined' ) module.exports = require('winax/activex');
function Log( aString ) {
	if ( typeof WScript !== 'undefined' ) {
		WScript.Echo( aString );
	} else {
		console.log( aString );
	}
	return;
}

Log( 'Starting...' );
var oApp = new ActiveXObject("Outlook.Application");
var oAccounts = oApp.Session.Accounts;
var oTheAccountToUse = null;
for (var accountIndex = 1; accountIndex <= oAccounts.Count; accountIndex++) {
	var oOneAccount = oAccounts.Item(accountIndex);
	if ( oOneAccount.SmtpAddress === 'some.adress@orange.fr' ) {
		oTheAccountToUse = oOneAccount;
		Log( 'Account Orange Found!' );
		break;
	} // endif
}
var oMail = oApp.CreateItem(0);
oMail.Recipients.Add('some.adress@google.com');
if ( typeof WScript !== 'undefined' ) {
	oMail.Subject = 'Test Mail with ActiveX CSCRIPT.EXE';
} else {
	oMail.Subject = 'Test Mail with ActiveX NODE.EXE';
}
if ( oTheAccountToUse !== null ) {
	Log( 'Setting Sender to: ' + oTheAccountToUse.SmtpAddress );
	oMail.SendUsingAccount = oTheAccountToUse;
	if ( oMail.SendUsingAccount === null ) {
		Log( 'oMail.SendUsingAccount seen as null !' );
	} else {
		Log( 'oMail.SendUsingAccount seen as NOT null !' );		
	}
}
oMail.Send();
Log('Sent!');

When using the above script with node.exe (and with correct strings for the addresses...) the output is:

Starting...
Account Orange Found!
Setting Sender to: some.adress@orange.fr
oMail.SendUsingAccount seen as null !
Sent!

So, the mail is sent, but not FROM the correct address/account

Hi durs, root cause FOUND!

If you look at the code of PutProperty in Microsoft's <atlcomcli.h>, you will find:

      if (pVar->vt == VT_UNKNOWN || pVar->vt == VT_DISPATCH ||
            (pVar->vt & VT_ARRAY) || (pVar->vt & VT_BYREF))
        {
            HRESULT hr = pDispatch->Invoke(dwDispID, IID_NULL,
                LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUTREF,

That "magic" is missing in your implementation. I added it, and my use case works!

Will submit a PR.