Page 1 of 1 1
Topic Options
#77964 - 2001-06-22 01:57 AM Sending Email using COM calls to CDO in KiX.
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
CDO is Collaboration Data Objects and it is a Component Object Model (COM) component designed to simplify writing programs that create or manipulate Internet messages. So, we should be able to use KiX's COM support to use CDO... we we can!

If you want more information about CDO in Win2000 have a look at MSDN's About CDO for Windows 2000 page. I have only used this script on Win2k with KiX Beta2a.

Be sure to put @@ in the email addresses too.


SendMail3.k2k

code:

break on
; send email with COM


$FromName="Mr Man."
$FromAddress="MrMan@@theInternet.com"


$ToName="you"
$ToAddress="your.email@@address.com"


$Subject="This is my first KiX email"
$Message="Hello, this is an email, blah blah blah.... :)"


$oMsg = CreateObject("CDO.Message")


$oMsg.From = '"'+$FromName+'"'+$FromAddress
$oMsg.To = '"'+$ToName+'"'+$ToAddress
$oMsg.Subject = $Subject
$oMsg.TextBody = $Message


"Sending..." ?


$oMsg.Send()


cj

------------------
cj's scripts page
cj's User Guide - 14 May 2001

chrismat@ozemail.com.au


 

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

Top
#77965 - 2001-06-25 08:50 PM Re: Sending Email using COM calls to CDO in KiX.
JensKalski Offline
Starting to like KiXtart

Registered: 2000-12-13
Posts: 186
Loc: Germany
Hello cj,
I've tried your script with the latest KiX2001 under german Windows2000 SP2.

The script runs and produdes no error-messages but also it produduces no eMail. Not in Outlook and not in Outlook Express and there is no traffic on my connection to the internet.

Where is the eMail gone to?

------------------
Jens Kalski
eMail: jens@kalski.de

_________________________
Jens Kalski

Top
#77966 - 2001-06-25 10:08 PM Re: Sending Email using COM calls to CDO in KiX.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Hi Jens and cj

I got the same results, but thought that perhaps our Firewall was the cause.

Mine does not send email either. I have English Windows 2000 SP2 and Outlook 2000

NTDOC

Top
#77967 - 2001-06-25 10:25 PM Re: Sending Email using COM calls to CDO in KiX.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
cj - if I can butt in for a moment - I don't know whats wrong but what happens if you guys put this in ...

$oMsg.Send()

?"ERROR @ERROR: @SERROR"


-Shawn

Top
#77968 - 2001-06-25 11:35 PM Re: Sending Email using COM calls to CDO in KiX.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Hi Shawn,

I get back this error:

code:
ERROR 1: COM exception error "Send" (CDO.Message.1 - The transport failed to connect to the server. 

I sent cj an email asking him how the system knows which Server and method to use, but I have not heard back yet.

I am using the KixTart 2001 v4.00 beta 2

NTDOC

Top
#77969 - 2001-06-26 10:37 AM Re: Sending Email using COM calls to CDO in KiX.
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
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).]

Top
#77970 - 2001-06-30 01:21 PM Re: Sending Email using COM calls to CDO in KiX.
Anonymous
Unregistered


I've done some work with CDO (v. handy if you run Exchange, but a bit of a bitch) and there are two varieties. (This is all NT4, don't know about W2K cos that's different again)

- (1) CDONTS (which I think is the CDOSYS version cj refers to) must be installed and run on an NT server to function. It comes with the Option Pack.
- (2) CDO v1.21 - Works with MAPI mail services, but really targetted at Exchange. It depends on logging into a profile (which can be anonymous) to get it's configuration i.e. what server to use etc.

W2K uses a new version of CDO which (I believe) is all SMTP based instead of MAPI. If you want to know what you've got installed on your machine, try opening Word, hitting <Alt>+F11 and going to Tool..References and looking for "Microsoft CDO ????????" in the list.

Hope it's useful (maybe, maybe not???)

MCD

Top
Page 1 of 1 1


Moderator:  ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 700 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.055 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.