I’m having a problem converting this VB6 code to VBScript. I’m calling out to a COM object to create an array as EmailAddressType. Here is the working VB6 Code:
'Assign TO: addresses
Dim toAdresses(2) As New EmailAddressType
toAdresses(0).EmailAddress = "someone@whocares.com"
toAdresses(0).RoutingType = "SMTP"
toAdresses(1).EmailAddress = "someoneelse@whocares.com"
toAdresses(1).RoutingType = "SMTP"
email.ToRecipients = toAdresses
I can’t seem to figure out how to convert this into VBScript. I’ve tried the following but just get a Type Mismatch error once I get to the email.ToRecipients = toAdresses
'Assign TO: addresses
dim toAdresses(2)
set toAdresses(0) = createobject("EWS.EWSWebSvc.EmailAddressType")
set toAdresses(1) = createobject("EWS.EWSWebSvc.EmailAddressType")
toAdresses(0).EmailAddress = "someone@whocares.com"
toAdresses(0).RoutingType = "SMTP"
toAdresses(1).EmailAddress = "someoneelse@whocares.com"
toAdresses(1).RoutingType = "SMTP"
email.ToRecipients = toAdresses
Btw this is a COM wrapper of the Exchange Web Services if that helps any.
I think the problem is that the .ToRecipients property wants an array of EmailAddressType while all you can easily get in VBScript is a Variant or array of Variants.
Looks like this API was just not built to be scriptable.
Oddly enough there is an implication it can be used from JScript though: MessageType.ToRecipients Property
I suspect they are rewriting history by gradually editing out any mention of VBScript on MSDN these days though.