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
Always about Outlook and OLE
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
- patdriscoll
- Posts: 16
- Joined: Tue May 19, 2009 7:28 pm
Re: Always about Outlook and OLE
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
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
Australia
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Re: Always about Outlook and OLE
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 ?
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
Marco Turco
SOFTWARE XP LLP
- Otto
- Posts: 6412
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 27 times
- Been thanked: 2 times
- Contact:
Re: Always about Outlook and OLE
Marco,
have you found a solution to this problem.
Thanks in advance
Otto
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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
Re: Always about Outlook and OLE
It looks like SendUsingAccount requires an object.
This is untested
This is untested
Code: Select all | Expand
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
- gkuhnert
- Posts: 274
- Joined: Fri Apr 04, 2008 1:25 pm
- Location: Aachen - Germany // Kerkrade - Netherlands
- Contact:
Re: Always about Outlook and OLE
This works and is tested for getting the accounts:
You just have to pick out the righ oAccount and use it, I assume.
Code: Select all | Expand
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.
- gkuhnert
- Posts: 274
- Joined: Fri Apr 04, 2008 1:25 pm
- Location: Aachen - Germany // Kerkrade - Netherlands
- Contact:
Re: Always about Outlook and OLE
Working:
Code: Select all | Expand
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