Download specified message header from POP3 & IMAP4 server.
[Syntax] C++: HRESULT GetMsgHeader( long nMsg, BSTR* pVal ) Visual Basic: GetMsgHeader( nMsg As long ) As String C#: string GetMsgHeader( long nMsg )
Parameters
nMsg
Ordinal number of message for message download. The minimum value is 1, the maximum value is returned by method GetTotalOfMails.
Return Value
This method returns raw string of message header. If it fails, the return value is null.
Remarks
This method abstracts message header without downloading the whole message body. With this feature, you can build an application such as POP3 & IMAP4 Checker to preview email. You can also use POPMSG object to parse email header as well as the whole email body.
Usage Example
[Visual Baisc]
Sub Rreview( pop3Server As String, pop3User As String, pop3Password As String )
Dim oPop3 As ANPOPLib.POPMAIN
Dim oMsg As ANPOPLib.POPMSG
Dim i, nRet, nSize, nCount As Integer
Dim emailContent, emailSubject, err As String
Set oPop3 = new ANPOPLib.POPMAIN 'Create object instance
Set oMsg = new ANPOPLib.POPMSG
'For IMAP4 server, please add the following code
'oPop3.IMAP4Connection = 1
'oPop3.ServerPort = 143
err = ""
nRet = oPop3.Connect( pop3Server, pop3User, pop3Password ) 'Connect pop3 server
If nRet <> 0 Then
err = "error with connecting server"
goto ErrorHandler
End If
nCount = oPop3.GetTotalOfMails() 'Get total count of emails
If nCount = -1 Then
err = "error with GetTotalOfMails"
goto ErrorHandler
ElseIf nCount = 0 Then
err = "no email"
goto ErrorHandler
End If
For i = 1 To nCount
emailContent = oPop3.GetMsgHeader(i) 'Retrieve email header
If emailContent = vbnullstring Then
err = "error with Retrieve"
goto ErrorHandler
End If
oMsg.RawContent = emailContent
emailSubject = oMsg.GetSubject() 'Rreview email subject
Next
ErrorHandler:
Call oPop3.Close() 'Close connection
Set oPop3 = Nothing
Set oMsg = Nothing
End Sub
[C#]
public void Preview( string pop3Server, string pop3User, string pop3Password )
{
POPMAINClass oPop3 = new POPMAINClass(); //Create object instance
POPMSGClass oMsg = new POPMSGClass();
int i = 0, nRet = 0, nSize = 0, nCount = 0;
string emailContent = "", emailSubject = "";
try
{
//For IMAP4 server, please add the following code
//oPop3.IMAP4Connection = 1;
//oPop3.ServerPort = 143;
nRet = oPop3.Connect( pop3Server,
pop3User,
pop3Password ); //Connect pop3 server
if( nRet != 0 )
throw new Exception( "error with Connect" );
nCount = oPop3.GetTotalOfMails(); //Get total count of emails
if( nCount == -1 )
throw new Exception( "error with GetTotalOfMails" );
else if( nCount == 0 )
throw new Exception( "no email" );
for( i = 1; i <= nCount; i++ )
{
emailContent = oPop3.GetMsgHeader(i); //Retrieve email headers
if( emailContent == null )
throw new Exception( "error with GetMsgHeader" );
oMsg.RawContent = emailContent;
emailSubject = oMsg.GetSubject() //get email subject
}
}
catch( Exception e )
{
Console.WriteLine( e.Message );
}
oPop3.Close(); //Close connection
oPop3 = null;
oMsg = null;
}
[Visual C++]
#include <comdef.h>
#include <string>
#include <iostream>
using namespace std;
#import "c:\program files\adminsystem.net\anpop\anpop.dll" no_namespace
VOID Rreview( const char* lpszServer,
const char* lpszUser,
const char* lpszPassword )
{
::CoInitialize( NULL );
IPOPMAINPtr oPop3("ANPOP.POPMAIN");
IPOPMSGPtr oMsg("ANPOP.POPMSG");
int i = 0, nCount = 0, nRet = 0, nSize = 0;
_bstr_t emailContent = "", emailSubject = "";
try
{
//For IMAP4 server, please add the following code
//oPop3->IMAP4Connection = 1;
//oPop3->ServerPort = 143;
nRet = oPop3->Connect( _bstr_t(lpszServer),
_bstr_t(lpszUser),
_bstr_t(lpszPassword));
if( nRet != 0 )
throw string( "error with Connect" );
nCount = oPop3->GetTotalOfMails(); //Get total count of emails
if( nCount == -1 )
throw string( "error with GetTotalOfMails" );
else if( nCount == 0 )
throw string( "no email" );
for( i = 1; i <= nCount; i++ )
{
emailContent = oPop3->GetMsgHeader(i); //Retrieve email header
if( emailContent == _bstr_t((BSTR)NULL))
throw string( "error with Retrieve" );
oMsg->RawContent = emailContent;
emailSubject = oMsg->GetSubject(); //preview email subject
}
}
catch( string &e )
{
cout << e << endl;
}
oPop3->Close(); //Close connection
oPop3.Release();
oMsg.Release();
::CoUninitialize();
}
See Also
Retrieve Method
GetTotalOfMails Method
Asynchronous mode
OnGetMsgHeader Event
OnError Event
2001-2007 © Copyright AdminSystem Software Limited. All rights reserved.