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!

Passing email addresses to Outlook 2003 from VFP 9

Status
Not open for further replies.

CEMrob

Programmer
Sep 2, 2008
24
GB
I have a screen in an application which allows users to select a number of email recipients from a table, and then to open up the user’s default mail client inserting the selected email addresses into the ‘to’, ‘cc’ or ‘bcc’ fields as appropriate. The user can then write the email text and send out the email in due course. It is a very simple process, and I do not need VFP to send the email.

The application is written in VFP9 SP2, and until recently all users were using Thunderbird as the mail client. Most machines are Windows XP, some are using Windows 7. I need a generic routine (ie not specific to Outlook 2003) as I do not know the email client for a given user.

The code below has worked perfectly for some years, but some users have now switched to Outlook 2003, using Word 2003 as the text editor, and although a new email document is still opened correctly, the recipient addresses are not put in. Am I missing something obvious?

*PREPARE FOR USING SHELLEXECUTE TO CALL EXTERNAL APPLICATIONS
DECLARE INTEGER ShellExecute IN shell32.dll ;
INTEGER hndWin, ;
STRING cAction, ;
STRING cFileName, ;
STRING cParams, ;
STRING cDir, ;
INTEGER nShowWin
**************************

* BUILD ADDRESS STRING TO SEND TO OPEN EMAIL CLIENT ROUTINE
SELECT massem && Table of recipients email addresses (field=’ownemail’),
COPY TO ARRAY aNms FIELDS ownemail FOR send=.t.
cAdds=""
GO top

* Build string of email addresses
FOR i=1 TO ALEN(aNms)
cAdds=cAdds+ALLTRIM(aNms)+","
ENDFOR
* Throw away last comma
cAdds=ALLTRIM(cAdds)
cAdds=LEFT(cAdds,LEN(cAdds)-1)

* User will have already selected whether recipients are 'To', 'CC', or 'BCC'.
* Build appropriate string
DO case
CASE thisform.optAddress.Value=1
cList="?To="
CASE thisform.optAddress.Value=2
cList="?CC="
CASE thisform.optAddress.Value=3
cList="?BCC="
ENDCASE
cList=cList+cAdds

=mail(1,cList)
**************************

PROCEDURE mail
PARAMETERS nDowhat,cAddresslist,

cAddresslist=alltrim(cAddresslist)
DO CASE
CASE nDowhat=1 && CREATE NEW EMAIL
cFileName = "mailto:"+cAddresslist
cAction = "open"
cParams=""
cDir=""
ENDCASE
errno=ShellExecute(0,cAction,cFileName,cParams,cDir,1)
 
Outlook 2003 is not the problem. ShellExecute with a [tt]mailto:[/tt] link (which is what you are doing) should work with Outlook just as it does with any other email client. I suspect the problem is that they are using Word as the text editor. Word does not know about [tt]mailto:[/tt], which is why it fails.

Is it possible for them to switch to using the default editor with Outlook? If they could try it, that would at least confirm or otherwise the above diagnosis.

If all fails, we can show you how to use Automation to do the job, but that's a big step up from where you are now, so let's try the easier solutions first.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks Mike. Persuading folk to use the default editor might be difficult, especially, as I say, I won't necessarily know which mail client, let alone which text editor, people will be using. Automation might be the only way forward. I will do some testing nonetheless.

Rob
 
Mike,
In Outlook > Options > Mail Format I have tested with 'Use Word etc' both checked and unchecked - same result, ie no addressees listed. Other than that altering setting, I can't see a way to change the default editor simply.

I have very briefly looked at Automation, but many years ago I developed methods of ways of transferring data to Word documents - and indeed to emails, so I have not gone into the subject in any detail. Any pointers would be welcome.
Rob
 
Rob,

Well, at least you've been able to rule out the use of Word as the editor. That was clearly a red herring. Sorry.

Regarding the use of Automation, here is some simple code that will get you started. The effect is similar to your use of ShellExecute(), in that it will display the message composing window, ready for the user to take some action:

Code:
oOut = CREATEOBJECT("outlook.application")
oMail = oOut.CreateItem(0)
oMail.Subject = "My subject"
oMail.To = "xxx@gmail.com"
oMail.Body = "My Message"
oMail.Display

Give it a try, and report back if you have any problems.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
Thank you very much. That does the trick, and I have tested sending an email to multiple recipients - that being the object of the exercise. I have little programming experience outside VFP, but I have looked at Microsoft's Outlook 2013 Developer reference, so can incorporate 'CC' and 'BCC' as necessary.

One question though, the users' emails should go out with a signature block, this being an html file with company logo, address etc. This is not coming up on the newly created email, and there isn't a '.signature' property available. I've messed about with .HTMLbody and one or two other properties, but no joy so far.

I am aware that it is not the purpose of this forum to provide lazy programmers with instant solutions (though I very much appreciate your help so far), so if this is a major issue, just point me in a suitable direction and I'll try and figure it for myself.
Rob
 
Rob,

HTMLBody is indeed the property you need. Use it in place of the Body property. As its name suggests, you need to store an HTML string there. This should be the entire text of the message, plus that of the signature.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You should not use a mailto: URI, as this is very limited and has a length limitation, which most probably is the reason it fails, not Outlook settings. Mike, using Word as mail editor, doesn't mean word is configured as mail client, this is simply a setting of outlook and will not make outlook interpret mailto: URIs different. Word is only involved behind the scenes, eg Words grammar and syntax checker are used.

You should also not use outlook.application, as that is onlöy automating outlook and no other mail client.


You either use the MAPI, either Simple or Extended.

Bye, Olaf.
 
You either use the MAPI, either Simple or Extended.

Olaf, my understanding is that Rob does not want to automate the sending of email, but rather he wants to display a partly-completed message-composing window for his users to interact with. I might be wrong about that, but if I'm not, he can use Automation for users who have Outlook, and mailto: for those with most other email clients.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You understood it correctly. You can do the same with MAPI, eg if you looked at Craig Boyds link about Extended MAPI, he offers an FLL that has both the functions EMSend() and EMDisplay().
You can do as much as composing a mail and displaying it or just create an empty mail with just recipients predefined and empty mail body, and then just display it.

Also using the MapiSession control or the MSMAPI.MAPISession, if you call mail.Send(.T.) you display the mail instead of sending it.

The MAPI (Mail API) was invented to do mail client unspecific mail automation and it offers all essential features and more.

Bye, Olaf.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top