Displaying a message
The sample displays contents of the message body.
Visual Basic code displays the body as plain text. If the message has HTML version only, MailBee automatically creates plain-text version.
ASP code displays the body as HTML. If the message has plain-text version only, it is converted into HTML.
Note: Advanced topics related to displaying HTML messages are discussed in the tutorials:
Displaying HTML-formatted messages in Visual Basic
Displaying HTML-formatted messages in ASP
Dim objPOP3, objMsg
' Create POP3 object
Set objPOP3 = CreateObject("MailBee.POP3")
' Enable logging POP3 session into a file
objPOP3.EnableLogging = True
objPOP3.LogFilePath = "C:\pop3_log.txt"
' Unlock POP3 object
objPOP3.LicenseKey = "put your license key here"
' Set POP3 server name
objPOP3.ServerName = "mail.server.com"
' Set user credentials
objPOP3.UserName = "username"
objPOP3.Password = "password"
' Connect to the server and log in the mailbox
If objPOP3.Connect Then
' Download first message completely
Set objMsg = objPOP3.RetrieveSingleMessage(1)
If Not objPOP3.IsError Then
' HTML message?
If objMsg.BodyFormat = 1 Then
' The message is HTML, so display
' plain version of HTML message body
MsgBox objMsg.AltBodyText
Else
' No, the message is not HTML,
' so display message body
MsgBox objMsg.BodyText
End If
Else
' Display error information
MsgBox "Error #" & objPOP3.ErrCode & ", " & objPOP3.ErrDesc
End If
' Close the connection
objPOP3.Disconnect
Else
' Display error information
MsgBox "Error #" & objPOP3.ErrCode
MsgBox "Server response: " & objPOP3.ServerResponse
End If
<%
Dim objPOP3, objMsg
' Create POP3 object
Set objPOP3 = Server.CreateObject("MailBee.POP3")
' Enable logging POP3 session into a file
objPOP3.EnableLogging = True
objPOP3.LogFilePath = "C:\pop3_log.txt"
' Unlock POP3 object
objPOP3.LicenseKey = "put your license key here"
' Set POP3 server name
objPOP3.ServerName = "mail.server.com"
' Set user credentials
objPOP3.UserName = "username"
objPOP3.Password = "password"
' Connect to the server and log in the mailbox
If objPOP3.Connect Then
' Download first message completely
Set objMsg = objPOP3.RetrieveSingleMessage(1)
If Not objPOP3.IsError Then
' HTML message?
If objMsg.BodyFormat = 1 Then
' The message is HTML, so
' display HTML message body
Response.Write objMsg.BodyText
Else
' The message is not HTML, so
' create HTML version of the body
Response.Write objMsg.GetHTMLFromPlain(objMsg.BodyText)
End If
Else
' Display error information
Response.Write "Error #" & objPOP3.ErrCode & ", " & objPOP3.ErrDesc
End If
' Close the connection
objPOP3.Disconnect
Else
' Display error information
Response.Write "Error #" & objPOP3.ErrCode & "<br>"
Response.Write "Server response: " & objPOP3.ServerResponse
End If
%>
See Also:
"Displaying HTML-formatted messages in Visual Basic" Tutorial
"Displaying HTML-formatted messages in ASP" Tutorial