Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can't get MAPI to send mail, always pops up exchange box
Message
From
24/02/1998 14:37:28
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Can't get MAPI to send mail, always pops up exchange box
Miscellaneous
Thread ID:
00080877
Message ID:
00080877
Views:
103
I am trying to get VFP to send an email with no user intervention. I used the code from the files section, but it always gives me an error on the send event, I can change it to ".send(1,1,0) and it will pop up the exchange box, but I want it to send automatically.

OK... When using send(1,0,0) I get error message "OLE lDispatch exception code 17389 from Active Messaging [Active Messaging - [E_FAIL{800040053}]]"

It is in my outbox, but it doesn't send.

I am running NT on a AST 233, Exchange 5.0 and the object identifies itself as "MAPI 1.0 SESSION (V 1.0)"

Also, the I don't understand the #INCLUDE statement at the beginning. The only file I got in the zip file was email.prg..

Could that be the problem?

*******************************************************************
*- EMAIL.PRG - EMAIL CODE FILE
*- Controls Communication with MS Exchange
*- Calls application object
*******************************************************************
*- Author : Matthew J. McDonnell, Jr.
*- Copywrite: 1997, all rights reserved
*******************************************************************
* - SYNOPSIS
* - The procedures and methods here are used to email and fax
*******************************************************************
*
#INCLUDE "INCLUDE\STRINGS.H"

sendinternetmail('tdaniel@nch.com','Test','This is a test of the Foxpro Email function.')

*-- One procedure to do it all
PROCEDURE SendInternetMail
PARAMETERS tcAddress, tcSubject, tcText

LOCAL loSess

loSess = EmailSession()
=SendMail(loSess, tcAddress, tcSubject, tcText)
loSess.logoff && If this procedure is not used (i.e. for multiple emails)
*- the logoff method must be called by the application that created the email session.


*-- Creates new email session, finds mailbox for current user
PROCEDURE EmailSession
LOCAL loSess

SET MESS TO "Logging Into Email Server....."
loSess = CREATEOBJECT("MAPI.Session")
loSess.logon('John Daniel') && - optional parameter is a profile, see above for using logoff

RETURN loSess

*-- Based on passed active email session, builds and sends email
PROCEDURE SendMail
*- Format for tcAddress:
*- FAX - "FAX:name@555-1234"
*- email - "joe@hisdomain.com"
PARAMETERS toSess, tcAddress, tcSubject, tcText

LOCAL loMsg, loAddr, lcEsc

SET MESS TO "Building Email....."

loMsg = toSess.outbox.messages.add && returns message/outbox object

loMsg.subject = tcSubject
loMsg.text = tcText
*- I haven't tested it yet, but I believe that the following code can be put in a
*- DO WHILE or FOR ENDFOR with the same object reference each pass in order to send
*- email to mulitiple recipients
loAddr = loMsg.recipients.add && returns address object

**** John Daniel
**
** I have to comment out this section due to an error message of "amibiguous recipient
****

* loAddr.AddressEntry.Type = IIF("FAX"$tcAddress, "FAX", "EMAIL")
* IF "FAX"$tcAddress
* loAddr.Name = SUBSTR(tcAddress, 5, LEN(tcAddress)-AT("@",tcAddress)-5)
* loAddr.Address = tcAddress
* loAddr.AddressEntry.Address = SUBSTR(tcAddress, 5)
* ELSE
* loAddr.Name = ALLT(tcAddress)
* ENDIF


loAddr.Name = ALLT(tcAddress)

loMsg.update && - update the outbox

SET MESS TO "Sending Message...."
loMsg.send(1,0,0)

SET MESS TO "Message Sent."

*- build a message
PROC EmailBody
#DEFINE HEADERLINE REPL('*', lnWidth)

LOCAL lcReturn, lnWidth, lnOldWidth, lnI

lnWidth = 70

lnOldWidth = SET('MEMOWIDTH')

SET MEMOWIDTH TO lnWidth

lcReturn = HEADERLINE + CRLF + ;
PADR(" Message From Application", lnWidth ) + CRLF + ;
PADR(" Automatically Generated by application ",lnWidth ) + CRLF + ;
HEADERLINE + CRLF

* - This would be where you would extract info from a table.
lcReturn = lcReturn + "This is the message" + CRLF + ;
HEADERLINE + CRLF + HEADERLINE

SET MEMOWIDTH TO lnOldWidth

RETURN lcReturn

This all works except for when I try to send mail I can't get it to just send it without popping up the Email window and pressing the send button. The command in question is

loMsg.send(1,1,0)

when I put anything else it doesn't work....

Can you help?
Reply
Map
View

Click here to load this message in the networking platform