Always about Outlook and OLE

Always about Outlook and OLE

Postby Marco Turco » Tue Jun 10, 2014 9:49 pm

Hi,
I have several emails accounts on Outlook.
For example: nick@softwarexp.co.uk (default), alan@softwarexp.co.uk, mary@softwarexp.co.uk.

How can I send an email via ole to Outlook using a sender different from the default account ? How for example can i send an email using the mary@softwarexp.co.uk account ?
Using the following code, the email is sent always using the default account (nick@softwarexp.co.uk)

oOutLook := TOleAuto():New("Outlook.Application")
oMailItem := oOutLook:CreateItem( 0 )
oRecip := oMailItem:Recipients

Thank you in advance
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Always about Outlook and OLE

Postby patdriscoll » Wed Jun 11, 2014 7:01 pm

Hi Marco,

Have you tried something like:

cAccount := "xyz@xyz.com"
oMailItem:SendUsingAccount := cAccount

where xhz@xyz.com is one of the accounts in your Outlook

Cheers,

Pat
Pat Driscoll
Australia
User avatar
patdriscoll
 
Posts: 16
Joined: Tue May 19, 2009 7:28 pm

Re: Always about Outlook and OLE

Postby Marco Turco » Fri Jun 13, 2014 10:20 am

Yes, tried with this code but the email is Always sent using the default Outlook account.

oOutLook := TOleAuto():New("Outlook.Application")
oMailItem := oOutLook:CreateItem( 0 )
oMailItem:SendUsingAccount := "xxxx@yyy.zzz"
oRecip := oMailItem:Recipients
..
..

Any ideas ?
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Always about Outlook and OLE

Postby Otto » Sat Apr 01, 2017 10:11 am

Marco,
have you found a solution to this problem.
Thanks in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6347
Joined: Fri Oct 07, 2005 7:07 pm

Re: Always about Outlook and OLE

Postby Gale FORd » Sat Apr 01, 2017 2:49 pm

It looks like SendUsingAccount requires an object.
This is untested
Code: Select all  Expand view  RUN

oOutLook := TOleAuto():New("Outlook.Application")
oAccount := oOutlook:Session:Accounts:Items( 1 )  // Default Account
For nCounter := 1 to len( oOutlook:Session:Accounts )
  if oOutlook:Session:Accounts:Items( nCounter ):SmtpAddress = "xxxx@yyy.zzz"
    oAccount :=  oOutlook:Session:Accounts:Items( nCounter )
    exit
  endif
next
oMailItem := oOutLook:CreateItem( 0 )
oMailItem:SendUsingAccount := oAccount
 
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Always about Outlook and OLE

Postby gkuhnert » Mon Jul 17, 2017 1:49 pm

This works and is tested for getting the accounts:

Code: Select all  Expand view  RUN
static function GetOutlookAccounts()
local aData := {}
local oAccounts, oAccount
local nI
    oOutlook := GetOutlookObject()
    IF oOutlook == nil
        return nil
    ENDIF
    oAccounts := oOutlook:Session:Accounts()
    FOR EACH oAccount in oAccounts
        aAdd(aData, {oAccount:SmtpAddress, oAccount:DisplayName, oAccount:UserName, oAccount:AccountType})
    NEXT
    xbrowse(aData)
return nil

static function GetOutlookObject()
    TRY
        oOutlook := GetActiveObject ( "Outlook.Application" )
    CATCH
        TRY
        oOutlook := CREATEOBJECT( "Outlook.Application" )
        CATCH
                MsgStop("Cannot start outlook.")
                return nil
            END
        END
return oOutlook

 


You just have to pick out the righ oAccount and use it, I assume.
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: Always about Outlook and OLE

Postby gkuhnert » Mon Jul 17, 2017 3:22 pm

Working:

Code: Select all  Expand view  RUN
static oOutlook

static function SendTestMail(cAddressTo, cAddressFrom)
local oMail
    GetOutlookObject()
    IF oOutlook == nil
        return nil
    ENDIF
    oMail := CreateOutlookMail(cAddressTo, cAddressFrom)
    oMail:Send()
return .t.

static function CreateOutlookMail(cAddressTo, cAddressFrom)
local oItem, oAccount
    oItem := oOutlook:Application:CreateItem(0)
    oItem:Subject := "Mail to myself"
    oItem:Body := "Body of my testmail"
    IF !empty(cAddress)
        oAccount := GetAccountByAddress(cAddressFrom)
        IF oAccount != nil
            oItem:SendUsingAccount := oAccount
        ENDIF
    ENDIF
    oItem:Recipients():Add(cAddressTo)
return oItem

static function GetAccountByAddress(cAddress)
local oTemp, oAccounts, oAccount
    oAccounts := oOutlook:Session:Accounts()
    FOR EACH oTemp in oAccounts
        IF upper(alltrim(oTemp:SmtpAddress)) == upper(alltrim(cAddress))
            oAccount := oTemp
        ENDIF
    NEXT
return oAccount

static function GetOutlookObject()
    TRY
        oOutlook := GetActiveObject ( "Outlook.Application" )
    CATCH
        TRY
        oOutlook := CREATEOBJECT( "Outlook.Application" )
        CATCH
                MsgStop("Cannot start outlook.")
                return nil
            END
        END
return osOutlook
 
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 52 guests