Mail.LoadFile Method


Loads a RFC822 message ( *.eml) file to current Mail instance.

[Visual Basic]
Public Sub LoadFile( _
    FileName As String, _
    LateLoadBody As Boolean 
)
[Visual C++]
public: HRESULT LoadFile(
    BSTR FileName,
    VARIANT_BOOL LateLoadBody
);

Parameters

FileName
A full file name (*.eml) of RFC822 message.
LateLoadBody
If this parameter is false, all content of the file will be loaded; If this parameter is true, this method only loads headers of the email to save memory, and will load all content automatically on demand.

Example

[Visual Basic 6.0, VBScript, Visual C++, Delphi] The following example demonstrates how to parse from, to, cc. To get the full samples of EAGetMail, please refer to Samples section.

[Visual Basic 6.0]
Private Sub ParseMailAddress()
    Dim oMail As New EAGetMailObjLib.Mail
    oMail.LicenseCode = "TryIt"
    oMail.LoadFile "c:\test.eml", True
    
    Dim oAddr As EAGetMailObjLib.MailAddress
    Set oAddr = oMail.ReplyTo
    MsgBox "Reply-To: " & oAddr.Name & "<" & oAddr.Address & ">"
    Set oAddr = oMail.From
    MsgBox "Reply-To: " & oAddr.Name & "<" & oAddr.Address & ">"
    
    Dim i, addressList
    Set addressList = oMail.ToList
    For i = 0 To addressList.Count - 1
        Set oAddr = addressList.Item(i)
        MsgBox "To: " & oAddr.Name & "<" & oAddr.Address & ">"
    Next
    
    Set addressList = oMail.CcList
    For i = 0 To addressList.Count - 1
        Set oAddr = addressList.Item(i)
        MsgBox "Cc: " & oAddr.Name & "<" & oAddr.Address & ">"
    Next
End Sub


[VBScript] Private Sub ParseMailAddress() Dim oMail Set oMail = CreateObject("EAGetMailObj.Mail") oMail.LicenseCode = "TryIt" oMail.LoadFile "c:\test.eml", True Dim oAddr Set oAddr = oMail.ReplyTo MsgBox "Reply-To: " & oAddr.Name & "<" & oAddr.Address & ">" Set oAddr = oMail.From MsgBox "Reply-To: " & oAddr.Name & "<" & oAddr.Address & ">" Dim i, addressList Set addressList = oMail.ToList For i = 0 To addressList.Count - 1 Set oAddr = addressList.Item(i) MsgBox "To: " & oAddr.Name & "<" & oAddr.Address & ">" Next Set addressList = oMail.CcList For i = 0 To addressList.Count - 1 Set oAddr = addressList.Item(i) MsgBox "Cc: " & oAddr.Name & "<" & oAddr.Address & ">" Next End Sub
[Visual C++] #include "stdafx.h" #include <windows.h> #include "eagetmailobj.tlh" using namespace EAGetMailObjLib; void ParseMailAddress() { ::CoInitialize(NULL); try { IMailPtr oMail; oMail.CreateInstance(__uuidof(EAGetMailObjLib::Mail)); oMail->LicenseCode = _T("TryIt"); oMail->LoadFile(_T("d:\\test.eml"), VARIANT_TRUE); IMailAddressPtr oAddr; oAddr = oMail->ReplyTo; _tprintf(_T("Reply-To: %s<%s>\r\n"), (TCHAR*)oAddr->Name, (TCHAR*)oAddr->Address); oAddr = oMail->From; _tprintf(_T("From: %s<%s>\r\n"), (TCHAR*)oAddr->Name, (TCHAR*)oAddr->Address); IAddressCollectionPtr addressList = oMail->ToList; for(LONG i = 0; i < addressList->Count; i++) { oAddr = addressList->GetItem(i); _tprintf(_T("To: %s<%s>\r\n"), (TCHAR*)oAddr->Name, (TCHAR*)oAddr->Address); } addressList = oMail->CcList; for(LONG i = 0; i < addressList->Count; i++) { oAddr = addressList->GetItem(i); _tprintf(_T("Cc: %s<%s>\r\n"), (TCHAR*)oAddr->Name, (TCHAR*)oAddr->Address); } } catch(_com_error &ep) { _tprintf(_T("%s\r\n"), (TCHAR*)ep.Description()); } ::CoUninitialize(); }
[Delphi] procedure ParseMailAddress(); Var oMail: TMail; i: Integer; addrs: IAddressCollection; addr: IMailAddress; begin oMail := TMail.Create(Application); oMail.LicenseCode := 'TryIt'; oMail.LoadFile('d:\test.eml', false); // Parse reply-to ShowMessage('Reply-To: ' + oMail.ReplyTo.Address); // Parse email sender ShowMessage('From: ' + oMail.From.Address); // Parse email to recipients addrs := oMail.ToList; for i := 0 To addrs.Count - 1 do begin addr := addrs.Item[i]; ShowMessage('To: ' + addr.Address); End; // Parse email cc recipients addrs := oMail.CcList; for i := 0 To addrs.Count - 1 do begin addr := addrs.Item[i]; ShowMessage('Cc: ' + addr.Address); end; end;

See Also

Mail.From Property
Mail.ToList Property
Mail.TextBody Property
Mail.HtmlBody Property
Mail.AttachmentList Property

Online Tutorials

Parse Email in VB6 - Tutorial
Parse Email in Delphi - Tutorial
Parse Email in VC++- Tutorial