TBH IDK how it works :D It just does for me...
Here is the source code in VBScript that I used:
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
' assume constants are defined within script file
.Item(cdoSendUsingMethod) = 2 ' cdoSendUsingPort
.Item(cdoSMTPServerName) = "email@example.com"
.Item(cdoSMTPConnectionTimeout) = 10 ' quick timeout
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "username"
.Item(cdoSendPassword) = "password"
.Item(cdoURLProxyServer) = "server:80"
.Item(cdoURLProxyBypass) = "<local>"
.Item(cdoURLGetLatestVersion) = True
Set .Configuration = iConf
.To = """User A"" <userA@microsoft.com>"
.From = """User B"" <userB@microsoft.com>"
.Subject = "Hows it going? I've attached my web page"
Now, that needed some tweaking and I couldn't get the ITEM() bits to work.
Here are the first two failed versions:
; send email with COM
$cdoSendUsingPort = 2
$StrSmartHost = "smarthost"
$iMsg = CreateObject("CDO.Message")
$iConf = CreateObject("CDO.Configuration")
$Flds = $iConf.Fields
; set the CDOSYS configuration fields to use port 25 on the SMTP server
; build HTML for message body
$strHTML = "<HTML>"
; apply the settings to the message
$iMsg.Configuration = $iConf
$iMsg.To = "firstname.lastname@example.org"
$iMsg.From = "email@example.com"
$iMsg.Subject = "This is a test CDOSYS message (Sent via Port 25)"
$iMsg.Body = $strHTML
; cleanup of variables
$iMsg = ""
$iConf = ""
$Flds = ""
; send email with COM
;Sending a Message via CDO
;Reference the project with CDO for Exchage 2000 and ADO 2.5 libraries
;Sending Mail Message Using Exchange Server
;Create a Message Object
$oMessage = CreateObject("CDO.Message")
;Set the properties
$oMessage.To = "firstname.lastname@example.org"
$oMessage.From = "email@example.com"
$oMessage.TextBody = "This is a sample Body"
$oMessage.Subject = "This is a sample Subject"
;$oMessage.Configuration.Fields("CdoSendUsing") = 3
Normally, you would set the server and login information in the CDO.Configuration object, but when I tried every combination of
$Flds.Item("sendusing") I couldn't make it work. Often I would get an error 100 (Cannot create another system semaphore.) too. I tried:
and others that I have not kept.
BTW 2 is SMTP and 3 is Exchange (i think). Have a look at that MSDN link and follow it down to the Messenging section. I suspect that one of the above lines worked and I ended up setting the parameters and they were remembered.
I only tried this for the novelty and didn't delve too deeply into the workings :}
[This message has been edited by cj (edited 26 June 2001).]