Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Automating Outlook
Message
De
27/12/2005 13:51:59
 
 
À
27/12/2005 11:02:56
Elyse Pomerantz
Dynamic Data Concepts, Inc.
Brooklyn, New York, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01080977
Message ID:
01081049
Vues:
18
Do you receive the error after the two lines you posted? After those two lines, you need to set a name or distribution list, etc before sending otherwise it returns an OLE IDispatch exception code 4096.

For testing purposes, please try (remember to change to .to value in the first example and the email address in the 2nd example first) these two code examples:
*--Automate Outlook
#DEFINE MAILITEM 0
#DEFINE IMPORTANCELOW 0
#DEFINE IMPORTANCENORMAL 1
#DEFINE IMPORTANCEHIGH 2

oOutLookObject = CreateObject("Outlook.Application")
oNS = oOutLookObject.GetNameSpace("MAPI")
oEmailItem = oOutLookObject.CreateItem(MAILITEM)

WITH oEmailItem
	.To = "you@youremail.com"
	.Subject = "Sending Email from within Foxpro to multiple recipients and with attachments"
	.Importance = IMPORTANCENORMAL
	.Body = "I'm now testing sending to multiple recipients in the .To value from within my app and mulitple attachments too."
	*.Attachments.Add("c:\temp\myfile.txt")
	*.Attachments.Add("C:\temp\junk.txt")
	.Display
	.Send
ENDWITH
RELEASE oEmailItem
RELEASE oOutLookObject
or
*--Send email using the user's default email client
sendemail('youremail@mail.com','Test Mail subject','This is the body.')

FUNCTION sendemail
LPARAMETERS tcRecipient,tcSubject,tcBody

*--Courtesy Rick Strahl, West-Wind Technologies
RETURN GoUrl("mailto:" + tcRecipient + ;
             "&Subject=" +STRTRAN(UrlEncode(tcSubject),"+"," ") +;
             "&Body=" + STRTRAN(UrlEncode(tcBody),"+"," "))


*----------------------------------------------------------------
FUNCTION GoUrl(tcUrl, tcAction, tcDirectory, tcParms)

IF EMPTY(tcUrl)
   RETURN -1
ENDIF

IF EMPTY(tcAction)
   tcAction = "OPEN"
ENDIF

IF EMPTY(tcDirectory)
   tcDirectory = SYS(2023) 
ENDIF

IF EMPTY(tcParms)
   tcParms = ""
ENDIF

DECLARE INTEGER ShellExecute ;
    IN SHELL32.dll ;
    INTEGER nWinHandle,;
    STRING cOperation,;
    STRING cFileName,;
    STRING cParameters,;
    STRING cDirectory,;
    INTEGER nShowWindow

DECLARE INTEGER FindWindow ;
   IN WIN32API STRING cNull,STRING cWinName

RETURN ShellExecute(FindWindow(0,_SCREEN.caption),;
                    tcAction,tcUrl,;
                    tcParms, tcDirectory,1)

*------------------------------------------------------------------
Function UrlEncode( tcValue, llNoPlus )

LOCAL lcResult, lcChar, lnSize, lnX
lcResult=""

FOR lnX=1 to len(tcValue)
   lcChar = SUBSTR(tcValue,lnX,1)
   IF ATC(lcChar,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") > 0
      lcResult=lcResult + lcChar
      LOOP
   ENDIF

   IF lcChar=" " AND !llNoPlus
      lcResult = lcResult + "+"
      LOOP
   ENDIF

   *** Convert others to Hex equivalents
   lcResult = lcResult + "%" + RIGHT(transform(ASC(lcChar),"@0"),2)
ENDFOR 
RETURN lcResult
>The following code is generating an error:
>
>loOutlook=CREATEOBJECT('outlook.application')
>loMessage = loOutlook.createitem(0)
>
>
>I have Outlook 2003. The error is "OLE IDispatch exception code 4096 from Microsoft Office Outlook: The operation failed..."
>
>Any ideas?
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform