Search The ForumSearch   RegisterRegister  LoginLogin

MailBee Objects

 AfterLogic Forum : MailBee Objects
Subject Topic: How to load a message from a database Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
John Muller
Newbie
Newbie


Joined: 18 October 2009
Online Status: Offline
Posts: 5
Posted: 30 October 2009 at 3:32am | IP Logged Quote John Muller

Hi,

I am storing my mails in a database and want to
load a message from a table. (Delphi)
The only method I found is "ImportFromFile". Is
there a way to load from a stream or anything
like this?

Thanks John
Back to Top View John Muller's Profile Search for other posts by John Muller
 
Andrew
AfterLogic Support
AfterLogic Support


Joined: 28 April 2006
Location: United States
Online Status: Offline
Posts: 1189
Posted: 30 October 2009 at 4:15am | IP Logged Quote Andrew

You can retrieve a message from a POP3 server and save its raw body into a database as follows (in VB6 syntax):

Code:
Dim oMailer, oMsg, sql, oRS, oConn
Set oMailer = CreateObject("MailBee.POP3")
Set oConn = CreateObject("ADODB.Connection")
Set oRS = CreateObject("ADODB.Recordset")

oMailer.LicenseKey = "put your license key here"

' Connect to the POP3 server
oMailer.Connect "mailserver.com", 110, "MyName", "MyPassword"

If oMailer.Connected Then

  If oMailer.MessageCount > 0 Then

    ' Retrieve the first message
    Set oMsg = oMailer.RetrieveSingleMessage(1)

    If Not oMsg Is Nothing Then

       ' Open connection to the database
       oConn.Open "Your connection string here"

       ' "Aim" for the messages table
       sql = "SELECT TOP 1 blob_body FROM messages"

       ' Open the cursor for insert into database
       oRS.CursorType = 3
       oRS.LockType = 4
       oRS.CursorLocation = 3
       oRS.Open sql, oConn

       ' Assign message raw body to the blob_body field
       oRS("blob_body").V alue = oMsg.RawBody

       ' Add new record to the database
       oRS.AddNew

       ' Close the recordset
       oRS.Close

       ' Close the connection to the database
       oConn.Close
    End If
    
  End If
  
  oMailer.Disconnect
End If


This sample downloads the first message from the POP3 mailbox, opens connection to database, "aims" for the messages table and inserts the new record with the message's raw body into the table. For MS SQL Server, the blob_body field should be of type TEXT.

You can get the raw body from the blob field in your database and assign it to the message object, then display body text of this object or another info as follows:

Code:
Dim sql, oRS, oMsg, oConn

Set oRS = CreateObject("ADODB.Recordset")
Set oConn = CreateObject("ADODB.Connection")

' Open connection to the database
oConn.Open "Your connection string here"

' Get raw body from blob field
sql = "SELECT blob_body FROM messages WHERE id = 10"
oRS.Open sql, oConn, 3, 3

If Not objRS.EOF

   ' Create empty object
   Set oMsg = CreateObject("MailBee.Message")

   ' Assign the raw body to the message
   oMsg.RawBody = oRS("blob_body").Value

   ' Display BodyText property
   MsgBox oMsg.BodyText
End If

' Close the recordset
oRS.Close

' Close the connection to the database
oConn.Close


Unfortunately, I don't have Delphi at hand right now, but I believe it's easy to translate this sample to Delphi.

Best regards,
Andrew
Back to Top View Andrew's Profile Search for other posts by Andrew
 
John Muller
Newbie
Newbie


Joined: 18 October 2009
Online Status: Offline
Posts: 5
Posted: 30 October 2009 at 6:51am | IP Logged Quote John Muller

Andrew,

thanks a lot: works like a charm.

Best regards John
Back to Top View John Muller's Profile Search for other posts by John Muller
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide