Problem with OLE and Outlook 2007

User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Problem with OLE and Outlook 2007

Post by driessen »

Hello,

I use this code to send email from my application :

Code: Select all

oOutLook := CreateObject("Outlook.Application")
oMail  := oOutLook:CreateItem(olMailItem)
oMail:Subject := ALLTRIM(EmOnde)
oMail:Body    := ALLTRIM(FmText)
oMail:Recipients:Add(cEmail[i])
oMail:CC  := TabCC
oMail:BCC := TabBCC
FOR j=1 TO LEN(TabBijl)
    oMail:Attachments:Add(TabBijl[j])
NEXT
oMail:HTMLBody := MEMOREAD(ALLTRIM(US->UOUTLSJAB))
oMail:Send()
When I was using Outlook 2000, XP or 2003, everything went just fine. Now I just started using Outlook 2007. If Outlook 2007 is opened, no problems occurs but if Outlook 2007 is not opened, I got an error :
Error discription : E_FAIL:Recepients

Win32ole => TOLEAUTO:RECIPIENTS
To prevent the error from happening, I have to open Outlook 2007 before I run my application.

But this wasn't the case with Outlook 2000, XP or 2003. I didn't need to open Outlook before running my application.

Can anyone tell me how this problem can be solved ?

Thank you.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Problem with OLE and Outlook 2007

Post by Enrico Maria Giordano »

Probably a bug in Outlook 2007. Can't you just open Outlook using ShellExecute() before your sendmail code?

EMG
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post by Otto »

Michel, how did you resolved the problem.

Thanks in advance
Otto
User avatar
NK
Posts: 97
Joined: Sun Nov 20, 2005 4:32 pm
Location: Germany
Contact:

Post by NK »

Have you test this way ?

Code: Select all

      oOutLook := CreateObject( "Outlook.Application" )
      oMail := oOutLook:CreateItem( 0 )
      oRecip := oMail:Recipients
      oRecip:Add( AllTrim( cTo ) )
Regards, Norbert
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post by Otto »

Norbert, thank you for your help.
But if Outlook - tests with VISTA and Office 2007 - is not started I get this error.
Regards,
Otto
PS: Privat:
Hallo Norbert,
ich habe über das Anfrageformular deiner Homepage vor einiger Zeit eine Anfrage gestellt. Hast du diese erhalten?
Gruß
Otto

Error occurred at: 03/09/08, 09:54:06
Error description: Error 2157156/0 S_OK: RECIPIENTS
Args:

Stack Calls
===========
Called from: => TOLEAUTO:RECIPIENTS(0)
Called from: test2007Email.prg => MAILSEND(145)
Called from: test2007Email.prg => (b)MAIN(37)
User avatar
NK
Posts: 97
Joined: Sun Nov 20, 2005 4:32 pm
Location: Germany
Contact:

Post by NK »

Otto wrote: PS: Privat:
Hallo Norbert,
ich habe über das Anfrageformular deiner Homepage vor einiger Zeit eine Anfrage gestellt. Hast du diese erhalten?
Sorry - nein. Schreib mir einfach eine Mail. Einfach auf die Taste "eMail"

Gruss, Norbert
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Post by driessen »

Otto,
Norbert,

I was able to solve the problem by using this code :

Code: Select all

oOutLook   := CreateObject("Outlook.Application")
oNameSpace := oOutlook:GetNameSpace("MAPI")
oMail  := oOutLook:CreateItem(olMailItem) 
oMail:Subject := ALLTRIM(EmOnde) 
oMail:Body    := ALLTRIM(FmText) 
oMail:Recipients:Add(cEmail[i]) 
oMail:CC  := TabCC 
oMail:BCC := TabBCC 
FOR j=1 TO LEN(TabBijl) 
    oMail:Attachments:Add(TabBijl[j]) 
NEXT 
oMail:HTMLBody := MEMOREAD(ALLTRIM(US->UOUTLSJAB)) 
oMail:Send()
I just added :

Code: Select all

oNameSpace := oOutlook:GetNameSpace("MAPI")
to my code.

Michel
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post by Otto »

Thanks Michael,
I tried the changes you suggested but the result is still the same.
Regards,
Otto
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post by Otto »

Hello Michael,
I found a solution for my problem:
If I use
oMail:To := "test@aon.at"
instead of:
oMail:Recipients:Add( "test@aon.at" )
all is working.

Regards,
Otto
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Post by driessen »

Otto,

But what happens in your solution when you have to send your email to several people ?

Michel
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post by Otto »

Michael, I successfully tried with a string like that: oMail:To := "test@aon.at;info@hotel.at;ruth@test.com;otto@aon.at"

Regards,
Otto
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Post by driessen »

Otto,

Thanks.

I'll try it out.

Michel
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
David Williams
Posts: 82
Joined: Fri Mar 03, 2006 6:26 pm
Location: Ireland

Outlook 2003 - A program is trying to send mail...

Post by David Williams »

Michel

How did you get around this when using outlook 2003?

"A program is trying to send mail using Item.Send"

You can buy a solution called ClickYes Pro for $40 but they are looking for multiple user licences.

Do you know of a simpler way around this?

Regards
David
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Post by Otto »

I am not sure if this is the same problem I had but maybe you can try:

HKEY_CURRENT_USER\ Software\ Microsoft\ Office\ <VERSION>\ Word\ Options

einen neuen DWORD-Wert anlegen mit dem Namen SQLSecurityCheck, der Wert ist 0

VERSION = "10.0" für Word 2002, "11.0" für Word 2003 und "12.0" für Word 2007.

Regards,
Otto
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

David,

>How did you get around this when using outlook 2003?

>"A program is trying to send mail using Item.Send"

With Outlook Express there is a setting under Options, Security that is:

"Warn me when other applications try to send mail as me."

Which you can turn off.

I expect that Outlook has the same setting somewhere.

James
Post Reply