Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get Emails in DBF
Message
From
15/03/2004 07:11:22
 
 
To
15/03/2004 02:47:04
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00886210
Message ID:
00886237
Views:
16
What should I write in the click event of cmd1 to get emials into dbf.

What are you using as your e-mail client? If you are using Outlook, you could get a copy of FoxTalk magazine from November 2002. In that magazine, Whil Hentzen had an article called "Look out! It's Outlook" that covers this exact topic and comes complete with source code.

Basically, you create a class to instantiate Outlook and call it like this:
LOCAL loMail, loRootFolder
loMail = CREATEOBJECT( 'sesOutlook' )
IF VARTYPE( loMail ) = 'O'
  WITH loMail
    loRootFolder = .oNameSpace.Folders(1)
      IF .ReadMail( loRootFolder )
        SET DATASESSION TO loMail.DataSessionID
        SELECT SaveMail
        BROWSE LAST
      ENDIF
  ENDWITH
ENDIF
RETURN
Here is the code for the ReadMail() method of the class:
*** The ReadMail Method goes through all the Outlook folders recursively and save all 
*** of the mailItems to the table OlMail.dbf. If the message has any attachments, 
*** it then calls the SaveAttachments method to save the attachment as a file on disk and 
*** insert a record with the name of the file into OlAttach.dbf along with a foreign key 
*** to the message in OlMail.dbf
LOCAL loItems, loItem, loFolders, loFolder

*** Get a local referenece to the collection of of items in the current folder
loItems = toFolder.Items

*** Process all the items in the current folder
*** If it is a mail item, save it and process the attachments
IF VARTYPE( loItems ) = 'O'
  FOR EACH loItem IN loItems
    IF loItem.Class = 43  && olMail	
      *** Add a record to the messages table
      *** store list of recipients as well
      lnCount = loItem.Recipients.Count
      m.lcRecip = ''
      FOR lnRecip = 1 TO lnCount
        loRecipient = loItem.Recipients[ lnRecip ]
        m.lcRecip = m.lcRecip + loRecipient.Name + ': ' + loRecipient.Address + CHR( 13 ) + CHR( 10 )
      ENDFOR

      *** First see if the sender name actually IS an e-mail address
      IF '@' $ loItem.SenderName
        m.lcSenderEm2 = loItem.SenderName
      else
        if empty(loItem.To)
          *** don't reply - this is just a draft
          m.lcSenderEm2 = "Draft"
        else
          loReply = loItem.Reply()
          loRecip = loReply.Recipients[ 1 ]
          m.lcSenderEm2 = IIF( NOT EMPTY( loRecip.Address ), loRecip.Address, loRecip.Name )
        endif
      ENDIF

      INSERT INTO SaveMail ( omInDate, omSender, omSubject, omBody, omFolder, omRecip, omSenderEm, omSenderEm2 ) ;
	VALUES ( loItem.ReceivedTime, loItem.SenderName, loItem.Subject, loItem.Body, toFolder.Name, m.lcRecip, m.lcSenderEm, m.lcSenderEm2 )
      
      *** Now see if we have attachments
      IF loItem.Attachments.Count > 0
	This.SaveAttachments( loItem )
      ENDIF
    ENDIF
  ENDFOR
ENDIF

*** Now see if this folder has folders to process
IF toFolder.Class = 2	&&	olFolder	
  loFolders = toFolder.Folders
  FOR EACH loFolder IN loFolders
    This.ReadMail( loFolder )
  ENDFOR
ENDIF
		
RETURN 
Previous
Reply
Map
View

Click here to load this message in the networking platform