• Welcome to Theos PowerBasic Museum 2017.

Sending Outlook Exchange EMail

Started by John Thompson, August 04, 2010, 05:01:08 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

John Thompson

I'd like to send an email, automatically, via Outlook and Exchange.  I started with MAPI,  which worked, but appeared to lack HTML formatting and required me to display the email prior to sending or required the user to 'allow' my program to send the email.  I'm trying to automate a process, so I'd prefer to skip that.

I moved to CDO, which appears to offer what I need, but I'm running into errors.

I started with the code from http://www.jose.it-berater.org/smfforum/index.php?topic=2719.0 and put this together:

#COMPILE EXE
#DIM ALL

#INCLUDE "CDOEX.INC"
#INCLUDE "OLE2UTILS.INC"

FUNCTION PBMAIN () AS LONG

    LOCAL oMessage          AS CDO_IMessage
    LOCAL oStream   AS ADOStream

    oMessage                = NEWCOM ( "CDO.Message" )
    IF ISNOTHING ( oMessage ) THEN EXIT FUNCTION

    TRY
        oMessage.To             = UCODE$("Lastname, Firstname;")
        oMessage.From           = UCODE$("Lastname, Firstname;")
        oMessage.Subject        = UCODE$("EMail")
        oMessage.TextBody       = UCODE$("Hi! Bye.")
        oMessage.HTMLBody       = UCODE$("<b>Hi!</b>Bye.")
        oMessage.AddAttachment UCODE$("C:\Documents and Settings\user\Desktop\experiment power point.ppt")
        oStream = oMessage.GetStream
        oStream.SaveToFile UCODE$("email.eml"), %adSaveCreateOverWrite
        oStream.Close
        oStream = NOTHING
        oMessage.Send
    CATCH
        OleShowErrorInfo OBJRESULT
    FINALLY
        oMessage = NOTHING
    END TRY

END FUNCTION


...but, I get this error:


Error code: &H80040220 [-2147220960]
Description: The "SendUsing" configuration value is invalid.

Source: CDO.Message.1


I tried making changes...


#COMPILE EXE
#DIM ALL

#INCLUDE "CDOEX.INC"
#INCLUDE "OLE2UTILS.INC"

FUNCTION PBMAIN () AS LONG

    LOCAL oMessage          AS CDO_IMessage
    LOCAL oConfiguration    AS CDO_IConfiguration
    LOCAL oBodyPart         AS CDO_IBodyParts
    LOCAL oFields           AS ADOFields
    LOCAL oField            AS ADOField
    LOCAL oStream   AS ADOStream

    oMessage                = NEWCOM ( "CDO.Message" )
    IF ISNOTHING ( oMessage ) THEN EXIT FUNCTION

    TRY
        oMessage.To             = UCODE$("Lastname, Firstname;")
        oMessage.From           = UCODE$("Lastname, Firstname")
        oMessage.Subject        = UCODE$("EMail")
        oMessage.TextBody       = UCODE$("Hi! Bye.")
        oMessage.HTMLBody       = UCODE$("<b>Hi!</b>Bye.")
        'oMessage.AddAttachment UCODE$("C:\Documents and Settings\user\Desktop\experiment power point.ppt")

        oConfiguration = oMessage.Configuration
        oFields = oConfiguration.Fields
        oField = oFields.Item ("CdoSendUsing")
        oField.Value = %cdoSendUsingExchange
        oFields.Update
        oField = NOTHING
        oFields = NOTHING

        oStream = oMessage.GetStream
        oStream.SaveToFile UCODE$("email.eml"), %adSaveCreateOverWrite
        oStream.Close
        oStream = NOTHING
        oMessage.Send
    CATCH
        OleShowErrorInfo OBJRESULT
    FINALLY
        oMessage = NOTHING
    END TRY

END FUNCTION


Can anyone help out with this error?

Thanks!

-John

José Roca

 
I don't have Exchange, so I can't test, but I think that


oFields.Item ("CdoSendUsing")


should be


oFields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")


See this thread: http://www.jose.it-berater.org/smfforum/index.php?topic=3076.15