Link to home
Start Free TrialLog in
Avatar of Emilio Morimoto
Emilio Morimoto

asked on

Store emails in MySql tables

In our application, written in VFP9, we would like to include a routine for store, in MySql tables, incoming and / or sent emails ( and then another routine to open these emails ).

Is that possible?

Translate from portuguese:

"Em nosso aplicativo, escrito em VFP9, gostaríamos de incluir uma rotina para armazenar, em tabelas MySql, emails recebidos e/ou enviados ( e, depois, outra rotina para abrir esses emails ).

Isto é possível? "
Avatar of Cyril Joudieh
Cyril Joudieh
Flag of Lebanon image

Of course that is possible but why do you wish to reinvent the wheel?

I mean there are software to store emails and contents and they have quite a wide range of utilities to go with that.

You can use CDONTS to send emails. It needs to be configured on a server and FoxPro can communicate with it quite well.

http://fox.wikis.com/wc.dll?Wiki~CdoEmail

http://support.microsoft.com/kb/186204
http://www.w3schools.com/asp/asp_send_email.asp
Avatar of Emilio Morimoto
Emilio Morimoto

ASKER

Grateful for the return.
I think that I could not explain the purpose of routine. I do not intend to send or receive mail through VFP. I wish I could choose some incoming and / or sent emails and store them in the database, linking them to customers folders.
For example, each order would have associated with it the confirmation email. Currently I print and keep it in pdf format. It would be nice to store the email itself.

Translate from portuguese:

"Grato pelo retorno.
Acho que não conseguí explicar o objetivo da rotina. Não pretendo enviar ou receber emails pelo VFP. Eu gostaria de poder escolher alguns emails recebidos e/ou enviados e guardá-los no banco de dados, associando-os a pastas de clientes.
Por exemplo, cada pedido teria a ele associado o email de confirmação. Atualmente eu imprimo e guardo no formato pdf. Seria ótimo poder armazenar o email em sí."
You can store the EML or MSG as a file in a fixed folder and store its name in the database. You will launch the EML or MSG file by using ShellExecute:

= ExecuteShell("d:\emailfolders\email.msg")

FUNCTION ExecuteShell
LPARAMETERS cFile, cOperation, cDefaultDirectory, cParameters
LOCAL nHwnd, cParameters, cDefaultDirectory, nShowWindow
DECLARE INTEGER ShellExecute IN shell32.dll AS ShellExecute;
      INTEGER nHwnd,;
      STRING @cOperation,;
      STRING @cFile,;
      STRING @cParameters,;
      STRING @cDefaultDirectory,;
      INTEGER nShowWindow
nHwnd = 0
cOperation = IIF(EMPTY(cOperation),'open',cOperation)
cParameters = IIF(EMPTY(cParameters),NULL,cParameters)
cDefaultDirectory = IIF(EMPTY(cDefaultDirectory),'',cDefaultDirectory)
nShowWindow = 1
= ShellExecute(nHwnd, @cOperation, @cFile, @cParameters, @cDefaultDirectory, nShowWindow)
CLEAR DLLS
I wish I could choose some incoming and / or sent emails and store them in the database

Do you mean the text from the body of the email?

Or do you mean a fully-pathed filename pointing to where the EML or MSG file (or the PDF file copy) is stored separately on your disk?

Precisely what information from the email do you want to store into the database data table?

Good Luck
ASKER CERTIFIED SOLUTION
Avatar of Cyril Joudieh
Cyril Joudieh
Flag of Lebanon image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Once solved, the question remains: why did not I think of that before?
The solution was obvious, and I could not see.

Thank you.

Translate from portuguese:

"Uma vez solucionado, fica a pergunta: porque eu não pensei nisso antes?
A solução estava na cara, e eu não conseguia enxergar.

Muito obrigado."
Well, we all tried many solutions and for different projects there are different solutions.

Today it is hard to communicate with Outlook. Before we could do a search of emails and have Outlook open one of them. If you do that, it might become unstable. Office 5/95/97/XP/2003 worked great in automation. The latest versions crash a lot except for Excel.
You can actually also automate the saveas method to save an outlook mail as msg file.

#Define olMSG 3
#Define olFolderInBox 6

oOutlook = CreateObject("outlook.application")
oMapi = oOutlook.GetNamespace('MAPI')
oMapi.Logon('accountname','password')
oFolder = oMapi.GetDefaultFolder(olFolderInBox)
oItem = oFolder.Items(1)
oItem.SaveAs('c:\temp\test1.msg',olMSG)

Open in new window


You can easily go from newest items to older ones by starting with Items.Count, instead of Items(1). a unique ID of each item is in it's oItem.EntryID property, so you can also see, which Items you already have exported, if you store that in your database. You can act on mail subject or body content or whatever.

You can also just store the EntryID and revisit that mail automagically inside Oulook via
oItem = oMapi.GetItemFromID(entryid stored into and read back from mySQL)
oItem.Display()

Open in new window


Of course that only works on the same client, having that outlook account open, but you can of course store a pst on a share and thereby allow access to many users, if the outlook account is some specifically for order mails.

Bye, Olaf.