TBH IDK how it works :D It just does for me...

Here is the source code in VBScript that I used:

code:

Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim iConf
Set iConf = CreateObject("CDO.Configuration")

Dim Flds
Set Flds = iConf.Fields

With Flds
' assume constants are defined within script file
.Item(cdoSendUsingMethod) = 2 ' cdoSendUsingPort
.Item(cdoSMTPServerName) = "somehost@microsoftc.om"
.Item(cdoSMTPConnectionTimeout) = 10 ' quick timeout
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "username"
.Item(cdoSendPassword) = "password"
.Item(cdoURLProxyServer) = "server:80"
.Item(cdoURLProxyBypass) = "<local>"
.Item(cdoURLGetLatestVersion) = True
.Update
End With

With iMsg
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"
.CreateMHTMLBody "http://mypage"
.AddAttachment "C:\files\mybook.doc"
.Send
End With


Now, that needed some tweaking and I couldn't get the ITEM() bits to work.

Here are the first two failed versions:

sendmail.k2k

code:

break on
cls

; send email with COM


Dim $iMsg
Dim $iConf
Dim $Flds
Dim $strHTML
Dim $strSmartHost

$cdoSendUsingPort = 2
$StrSmartHost = "smarthost"

$iMsg = CreateObject("CDO.Message")
@error ?
$iConf = CreateObject("CDO.Configuration")

@error ?
$Flds = $iConf.Fields
@error ?

; set the CDOSYS configuration fields to use port 25 on the SMTP server

$Flds.Item("sendusing")=2;=$cdoSendUsingPort
@error ?
; http://schemas.microsoft.com/cdo/configuration/
$Flds.Item("smtpserver")="smtp.ipass.ozemail.com.au" ;);=$strSmartHost
@error ?
$Flds.Item("smtpconnectiontimeout=10");=10
@error ?
$Flds.Update()
@error ?

; build HTML for message body
$strHTML = "<HTML>"

; apply the settings to the message

$iMsg.Configuration = $iConf
@error ?
$iMsg.To = "chrismat@ozemail.com.au"
@error ?
$iMsg.From = "chrismat@ozemail.com"
@error ?
$iMsg.Subject = "This is a test CDOSYS message (Sent via Port 25)"
@error ?
$iMsg.Body = $strHTML
@error ?
$iMsg.Send()
@error ?


; cleanup of variables
$iMsg = ""
$iConf = ""
$Flds = ""


Sendmail2.k2k

code:

break on
?

; 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

Dim $oMessage
;Create a Message Object
$oMessage = CreateObject("CDO.Message")
vartypename($oMessage) ?

;Set the properties
$oMessage.To = "chrismat@ozemail.com.au"
$oMessage.From = "chrismat@ozemail.com"
$oMessage.TextBody = "This is a sample Body"
$oMessage.Subject = "This is a sample Subject"

;$oMessage.Configuration.Fields("CdoSendUsing") = 3

;$oMessage.Configuration.Fields.Update()

;$oMessage.AddAttachment ("c:\file1.txt")
;$oMessage.CreateMHTMLBody "http://www.microsoft.com"

$oMessage.Send()
@error ?

?


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:

$Flds.Item("sendusing")=2
$Flds.Item("sendusing", 2)
$Flds.Item.sendusing=2
$Flds.Item.sendusing()=2

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 :}

HTH

cj

[This message has been edited by cj (edited 26 June 2001).]