Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Notification that email has been deliveried 2

Status
Not open for further replies.

DHart

Programmer
Oct 29, 2001
11
US
Is there code that can be added to my Visual FoxPro program so that the mail server will send an email notification that the email was deliveried?


procedure deliver_mail
if empty(m.subject) .or. empty(m.text) .or. empty(m.recipient)
wait window "Missing Email Header Data... Program Will Exit" timeout 1
return
else

***** Memory Variable Setup For Automatic Email
mprofile = "Microsoft Outlook" && Email Profile

***************************************************
*Create a MAPI Session object then Logon. The Logon dialog can be
*bypassed by providing a valid ProfileName as the first parameter
*(as a string) to the Logon Method as seen below.
objSession = CREATEOBJECT("mapi.session")
objSession.Logon(mprofile)
*Create a new message in the Outbox and populate a few basic properties
objMessage = objSession.Outbox.Messages.Add
objMessage.Subject = m.subject
objMessage.Text = m.text
*Add an attachment (assumes "myfile.doc" exist in c:\)
if empty(m.attachment1)
Wait Window " No Attachment To Send...." nowait
else
Wait Window "Attachments Will Be Sent...." nowait
objMessage.Attachments.Add(m.attachment1, 0, 1, m.attachment1)
objMessage.Attachments.Add(m.attachment2, 1, 1, m.attachment2)
endif
*Add a Recipient to the message we just created and resolve
objRecip = objMessage.Recipients.Add(m.recipient) && who it's to
objRecip.Resolve
*Send it
objMessage.Send
*Clean up then bail
objSession.Logoff
RELEASE objRecip, objMessage, objSession
endif

Thanks,
DHart
 
Since A MAPI session is not really a OLE Automation, it is difficult to figure out how to set the "Request a read receipt" option to true.
It would be easier if you were to Automate Outlook.
For example if you take Ramani's FAQ184-766 and add one line you would have what you need:


o=createobject("outlook.application")
oitem=o.createitem(0)
oItem.ReadReceiptRequested=.t. this line added
oitem.subject="Email From VFP6"
oitem.to="ramani_g@yahoo.com"
oitem.body="This mail was sent from vfp using Outlook98"
oitem.Attachments.Add("MyFullPath+MyFile+Ext")
oitem.send
o=.null.

Mike Gagnon
comp14.gif
 
DHart

Although my suggestion does not prevent the receipient to refuse to acknowledge the request.
Mike Gagnon
comp14.gif
 
I made this change. It works GREAT when I send only one attachment. When I attempt to send two attachments in the same email, the second one attaches as a shortcut to the actual file. Due to network security, some receipents cannot read the doc.

Thanks for all the help,
DHart
 
DHart

I was able to send two files succesfully with this method:
Code:
#DEFINE MAILITEM 0
#DEFINE IMPORTANCELOW 0
#DEFINE IMPORTANCENORMAL 1
#DEFINE IMPORTANCEHIGH 2

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

WITH oEmailItem
   .Recipients.Add("me@mydomain.com") && uses the Recipients collection
   .Subject = "Automation sample"
   .Importance = IMPORTANCENORMAL
   .Body = "This is easy!"
   .Attachments.Add("c:\printer.fxp") && Note that the fully qualified path and file is required.
   .Attachments.Add("c:\printer.bak")
   .Send
ENDWITH

RELEASE oEmailItem
RELEASE oOutLookObject

Mike Gagnon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top