INT OpenMessage( |
|
UINT nMessageId |
|
); |
The OpenMessage method opens the specified message for
reading.
Parameters
- nMessageId
- Number that specifies which message to open. This value must be
greater than zero. The first message in the mailbox is message
one.
Return Value
If the method succeeds, the return value is zero. If the method
fails, the return value is POP_ERROR. To get extended error
information, call GetLastError.
Remarks
The OpenMessage method is used to begin the process of
reading the contents of a message from the from the server. Similar
to how a file is opened and read, this method is followed by one or
more calls to the Read method. When the entire contents of the
message has been read, the CloseMessage method is used to
close the message, completing the transaction on the server.
This is a lower-level method which enables the application to
process the message as the contents are being returned by the server.
In general, it is recommended that most applications use the
GetMessage method instead, which provides a simpler interface
for retrieving the contents of a message.
It is important to note that you cannot use this method to read
the partial contents of a message. Opening a message on the server
begins a process where the entire message contents must be read and
the message closed before the next command can be issued to the
server. If you only want to obtain the headers for a message, use the
GetMessageHeaders method instead.
Example
// Connect to the mail server using the default settings
if (popClient.Connect(strHostName))
{
// Authenticate the user and display an error if the
// server does not accept the username or password
if (popClient.Login(strUserName, strPassword) == POP_ERROR)
{
popClient.ShowError();
popClient.Disconnect();
return;
}
// Open the specified message
if (popClient.OpenMessage(nMessageId) == POP_ERROR)
{
popClient.ShowError();
popClient.Disconnect();
return;
}
CString strMessage;
CString strBuffer;
INT nResult;
// Read the contents of the message in a loop; a return value
// of zero indicates that there is no more data to read
do
{
if ((nResult = popClient.Read(strBuffer)) > 0)
strMessage = strMessage + strBuffer;
}
while (nResult > 0);
// If an error occurred while reading reading the message,
// display an error message
if (nResult == POP_ERROR)
{
popClient.ShowError();
popClient.Disconnect();
return;
}
// Close the message and disconnect from the server
popClient.CloseMessage();
popClient.Disconnect();
}
Requirements
Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header File: cstools10.h
Import Library: cspopv10.lib
See Also
CloseMessage,
GetMessage,
GetMessageHeaders,
IsReadable, Read
|