Link to home
Start Free TrialLog in
Avatar of APD Toronto
APD TorontoFlag for Canada

asked on

Setting Library Reference by code / Using CDOSYS in a .vbs file

Hello Experts,

I have the following code which is pretty simple and works in VB6, but when I copy it into a VBS file and comment out the 2 Form_Load lines I get the following error at line 22:

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

Also, in VB6 I can get the same error if I remove the reference to the Microsoft CDO Message library. I guess, my question should be how can I set a Reference to C:\windows\system32\cdosys.dll by code within my .vbs file?

Thank you,
'Option Explicit

Private Sub Form_Load() '**************COMMENT OUT FOR VBS******************
    Call testMail
End Sub '**************COMMENT OUT FOR VBS******************

Sub testMail()
    
    smtpServer = "smtpout.secureserver.net"
    smtpUser = "testing@m-p-c.org"
    smtpPass = "testing"
    fromAddress = "testing@m-p-c.org"
    
    toAddress = "aleks@aces-project.com"
    body = "testing"
    subject = "cdo test"
    
   
     Set cdoConfig = CreateObject("CDO.Configuration")
 
     With cdoConfig.Fields
        .Item(cdoSendUsingMethod) = cdoSendUsingPort
        .Item(cdoSMTPServer) = smtpServer
        .Item(cdoSMTPAuthenticate) = 1
        .Item(cdoSendUsername) = smtpUser
        .Item(cdoSendPassword) = smtpPass
        '.Item("cdoSMTPServerPort") = 45
        .Update
    End With

 
    Set cdoMessage = CreateObject("CDO.Message")
 
    With cdoMessage
        Set .Configuration = cdoConfig
        
        .From = fromAddress
        .To = toAddress
        .subject = subject
        .HTMLBody = body
        
        .Send
    End With
 
    Set cdoMessage = Nothing
    Set cdoConfig = Nothing
    
    MsgBox "done."

End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of APD Toronto

ASKER

THANK YOU