Read Mails from Outlook n store in SQLServer

D

diya gp

Well my requirement is that i want to read the mails from

Outlook and store it in the Database and then delete the stored mails.
have writen the code in Vb which i would want to be written in VbScript
later,
Also Want to write the code in VB 6 without using the MAPI controls.
I have the following code,but am getting an error at the following line
error :-
"Active x Component cannot create object"

Set oSession = CreateObject("MAPI.Session")

The whole code is as follows

Dim oSession As object
Dim oFolder As Object
Dim oMessages As Object
Dim oMsg As Object
Dim oAttachments As Object
'//Varible Define To Pass The Paramater in Function
Dim strEmailToAdd As String
Dim strEmailFromAdd As String
Dim strEmailBody As String
Dim strEmailSubject As String
Dim EmailRecivedDate As Date
Dim EmailSendDate As Date

Set oSession = CreateObject("MAPI.Session")

oSession.Logon "developer5", , True, True

Set oFolder = oSession.Inbox
Set oMessages = oFolder.Messages

Set oMsg = oMessages.GetFirst
Screen.MousePointer = vbHourglass ' the DeliverNow method could take a
while right?
oSession.DeliverNow ' this now gets all mail services sent and
delivered just as the menu option, tools/deliver now/all services does
'
While Not oMsg Is Nothing ' If the message collection was empty, oMsg
should be equal to the Nothing object, not "Is" operator takes object
inputs
If oMsg.Unread = False Then
strEmailToAdd = oMsg.Sender.Address
strEmailFromAdd = oMsg.Sender.Address
strEmailBody = Trim(Replace(oMsg.Text, "'", """"))
strEmailSubject = Trim(Replace(oMsg.Subject, "'", "''"))
EmailRecivedDate = oMsg.TimeReceived
EmailSendDate = oMsg.TimeSent
End If
Set oMsg = oMessages.GetNext
Wend
Screen.MousePointer = vbDefault ' delivery is now complete so let
them know
'Explicitly release objects.
oSession.Logoff
Set oSession = Nothing
End If

msgbox(strEmailToAdd ,vbInformation)
msgbox(strEmailFromAdd ,vbInformation)
msgbox(strEmailBody ,vbInformation)

Want help/information about how to create a Mapi.session so as to read
the mails from Microsoft Outlook



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
S

Sue Mosher [MVP-Outlook]

MAPI.Session refers to CDO 1.21. Do you have a reference to that library in
your VB project?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top