Jump to content

Recommended Posts

Posted

I want to set configuration constants for a COM object in AutoIt. It works fine in vb, but I don't know how to convert it to autoit. Here's the snippet of code I have so far:

$objMessage = ObjCreate("CDO.Message")
$objMessage.Subject = "Test Message"
$objMessage.Sender = "Anonymous User <bob@anonymous.com>"
$objMessage.To = "user@domain.com"
$objMessage.TextBody = "This is a test message."

$test = "Subject: " & $objMessage.Subject & @LF & "Sender: " & $objMessage.Sender & @LF & "To: " & $objMessage.To & @LF & "Body: " & $objMessage.TextBody
MsgBox(0, "test", $test)

;Everything above this works

; STMP Server Settings
    $objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = "2"
    $objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.cait.scps.k12.fl.us"
    $objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = "cdoNone";'can also be Basic or NTLM
    $objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = "25"
    $objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = "60"
    $objMessage.Configuration.Fields.Update
; SMTP Server Settings Complete

$objMessage.Send

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Posted

This works for me on XP Pro SP2

; Initialize my error handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$objMessage = ObjCreate("CDO.Message")
$objMessage.Subject = "Test Message"
$objMessage.Sender = "SenderName <sender@email.address>"
$objMessage.From = "SenderName <sender@email.address>"
$objMessage.To = "recipient@email.address"
$objMessage.TextBody = "This is a test message."

$test = "Subject: " & $objMessage.Subject & @LF & _ 
        "Sender: " & $objMessage.Sender & @LF & _ 
        "To: " & $objMessage.To & @LF & _ 
        "Body: " & $objMessage.TextBody
MsgBox(0, "test", $test)

;Everything above this works

; STMP Server Settings
With $objMessage.Configuration.Fields
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.server.address"
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "pasword"
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    .Update
EndWith
; SMTP Server Settings Complete

$objMessage.Send

; This is my custom error handler
Func MyErrFunc()

  $HexNumber=hex($oMyError.number,8)

  Msgbox(0,"","We intercepted a COM Error !"       & @CRLF                        & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )

  SetError(1) ; to check for after this function returns
Endfunc

I added the COM error handler from Sven's example.

I also needed to authenticate to my SMTP server hence the extra 2 fields and smtpauthenticate set to cdoBasic (1) instead of cdoNone (0).

Posted (edited)

Thanks for that actually, now, to see how to do NTLM authentication!

(Just returned from a BPA conference, back to working on my scripts :))

Edit: hum...not working with my email server...

Edited by MSLx Fanboy

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...