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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email automation with Outlook 2007 and 2003

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
0
0
GB

Hi all

We have an app that automatically sends confirmation emails when an order is processed. There have been no problems using this with Outlook 2007 in conjunction with ClickYesPro (which stops the "Someone is trying to send... message")

Today, we tried this out at another location where Outlook 2003 is the email software and get the following error message:
OLE IDispatch exception code 4096 from Microsoft Office Outlook: The operation failed....
Seems strange that it works with a later version of Outlook but not with an earlier one.

Here is part of the code we use:
Code:
oOutlook = Createobject('Outlook.Application')
oNameSpace = oOutlook.getnamespace('MAPI')
oOutbox = oNameSpace.GetDefaultFolder(4)
oItems = oOutbox.Items
oMailItem = oItems.Add(0)
oMailItem.To = memail
	    
oMailItem.Subject = "Our subject line here"

oMailItem.HTMLBody = EXTRA+"<HTML><BODY> ;
  <br>Dear "+proper(mline01)+"</B> ;
  <br><br>Many thanks for your order. ;
  <br><br>Order id:  <B>"+TRIM(mtransact)+"</B> ;
  <br><br>Order details: <B>"+TRIM(mordtext)+"</B> ;

  [b]edited....[/b]

  <br><br>Many thanks ;
  </BODY></HTML>"

oMailItem.Send
I seem to recall that there was some reference to Outlook 2003 as being Outlook11 and 2007 being Outlook12 but I'm not sure if this has relevance or significance as to why this won't work on an earlier version.

I would appreciate your guidance on this one.

Many thanks

Lee
 
Problem resolved. It appears that Outlook 2003 should be open when running the automated process.

We have tried this and it works in both 2003 and 2007.

Windows Vista
Visual FoxPro Versions 6 & 9
 
Lee,

I'm very interested to hear you say that Outlook 2003 needs to be running in order for your VFP app to send emails through it.

I have a similar problem with my app. In my case there's no error as such - the email just ends up in the user's inbox marked as not having been sent.

I asked a question about this here ages back and the response I got was suggesting that Outlook wasn't installed properly (or something like that). I couldn't see that that was the case as other applications are able to email through Outlook when it's not running.

Did you find that to be the case?

It would be interesting to hear from anyone who might have a solution to this issue.

Stewart
 
Stewart

We did notice that if we sent a few emails by the automation process with Outlook closed, they did stay in the inbox until someone hit the send/receive command.

As you are aware, this is not very efficient and because our client is dealing with hundreds of orders on a daily basis, he is required to send an initial "Thank you for your order which is being processed" type email and a further "Your order has been disptached" email.

Processing these emails with a set up of ClickYesPro, Outlook 2003 or 2007 open at the time, deals with them in seconds.

We only picked this fact up because when the ClickYesPro is mamximised (There is however no requirement to do this) we noticed that it shows you Outlook as a running process when it is open.

Needless to say, we ran tests aftet this and they worked.

You mentioned:
I asked a question about this here ages back and the response I got was suggesting that Outlook wasn't installed properly (or something like that). I couldn't see that that was the case as other applications are able to email through Outlook when it's not running.

I tend to agree with you as we spent sometime trying to perfect this and with the advice we were given, resolved it very efficiently.

I didn't mention that we were using Version 6 of VFP for this project and it has not been tested with V9.

Hope that helps you in your quest!

Lee



Windows Vista
Visual FoxPro Versions 6 & 9
 
I use the following similar code along with MapiLabs Advanced Outlook Security(free) to automate emails with outlook running or with outlook not running in the background. It seems to work from w2000 thru w2003 server os's without errors.
Code:
o=createobject("outlook.application")
oNameSpace = o.GetNameSpace('MAPI')
oExplorer = o.Explorers.add(oNameSpace.Folders[1],1)

oitem=o.createitem(0)
oitem.subject=csubject
oitem.to=cemailadd
*oitem.bcc="emailname@emailaddress"  && this causes an error
oitem.bcc=&cbcc
oitem.body=CBODY
oitem.attachments.add(&COBFILENAME)

oitem.send

FOR EACH Thing IN oNamespace.syncobjects
	oFoo = Thing
	oFoo.start
ENDFOR

o=.null.

RELEASE ALL LIKE o
As i recall the For Each loop which i got from outlookcode.com forces stuck items out of the drafts folder.
wjwjr

This old world keeps spinning round - It's a wonder tall trees ain't layin' down
 
If it helps anyone reading this thread, our code stores fields from a table and uses another table to store HTML coding. Example:
Code:
tmpemail=SYS(3)

SELECT * FROM OURTABLE WHERE (Condition here) ;
  ORDER BY LINE01 INTO TABLE tmpemail+'.dbf'

DO WHILE NOT EOF()
  WAIT "Processing record: "+LTRIM(STR(RECNO()))+" of "+ ;
    LTRIM(STR(mrecs)) WINDOW NOWAIT

  mrecno=0
  mrecno=RECNO()
  mcusturn=0
  mcusturn=URN
  
  DO FINDDISP

  USE tmpemail+'.dbf'
  GO mrecno
  SKIP
ENDDO
RETURN

*************
PROC FINDDISP
*************

USE OURTABLE ORDER URN
GO TOP

IF SEEK(mcusturn)
  mthis=0
  mthis=RECNO()

  Edited - Field tables stored to variables here

  USE HTMLTABLE

  [b]oOutlook = Createobject('Outlook.Application')
  oNameSpace = oOutlook.getnamespace('MAPI')
  oOutbox = oNameSpace.GetDefaultFolder(4)
  oItems = oOutbox.Items
  oMailItem = oItems.Add(0)
  oMailItem.To = memail
	    
  oMailItem.Subject = "Our email message dispatch notification [ "+ ;
    TRIM(mtransact)+" ] from our company"

  oMailItem.HTMLBody = EXTRA+"<HTML><BODY> ;
    <br>Dear "+proper(mline01)+"</B> ;
    <br><br>Many thanks for your order. ;
    <br><br>Order id:  <B>"+TRIM(mtransact)+"</B> ;
    <br><br>Order details: <B>"+TRIM(mordtext)+"</B> ;
    <br><br>This order has been dispatched from our...... ;

    Edited

    <br><B>"+TRIM(proper(mline07))+"</B> ;
    <br><B>"+TRIM(proper(mline08))+"</B> ;
    <br>Many thanks ;
    <br><br><B>Our Company</B> ;
    <br><br>"+TRIM(TXTEMAIL)+" ;
    </BODY></HTML>"
		
  oMailItem.Send[/b]

  CLOSE DATABASES
		
  USE OURTABLE
  GO mthis

* UPDATE THE RECORD BEFORE WE MOVE ON

  REPLACE EMAILCONFM	WITH "Y"
  REPLACE EMAILSENT	WITH DATE()
			
  REPLACE EMORDSENT	WITH "Y"
  REPLACE EMORDDATE	WITH DATE()

ENDI
	
WAIT CLEAR
CLOSE DATABASES
CLEAR
RETURN
Lee


Windows Vista
Visual FoxPro Versions 6 & 9
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top