Author |
|
John Muller Newbie
Joined: 18 October 2009
Online Status: Offline Posts: 5
|
Posted: 30 October 2009 at 3:32am | IP Logged
|
|
|
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 |
|
|
Andrew AfterLogic Support
Joined: 28 April 2006 Location: United States
Online Status: Offline Posts: 1189
|
Posted: 30 October 2009 at 4:15am | IP Logged
|
|
|
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 |
|
|
John Muller Newbie
Joined: 18 October 2009
Online Status: Offline Posts: 5
|
Posted: 30 October 2009 at 6:51am | IP Logged
|
|
|
Andrew,
thanks a lot: works like a charm.
Best regards John
|
Back to Top |
|
|