MailAdress Object


Provides properties and methods for presenting an e-mail address including display name, e-mail address.

IDispatch
    IMailAddress

[Visual Basic 6.0]
Public Class MailAddress
[Visual C++]
public: interface IMailAddress

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Public Properties

Address Gets the e-mail address.
Name Gets the display name.

Example

[Visual Basic 6.0, VBScript, Visual C++] 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 arAddr
    arAddr = oMail.To
    Dim i
    For i = LBound(arAddr) To UBound(arAddr)
        Set oAddr = arAddr(i)
        MsgBox "To: " & oAddr.Name & "<" & oAddr.Address & ">"
    Next
    
    arAddr = oMail.Cc
    For i = LBound(arAddr) To UBound(arAddr)
        Set oAddr = arAddr(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 arAddr
    arAddr = oMail.To
    Dim i
    For i = LBound(arAddr) To UBound(arAddr)
        Set oAddr = arAddr(i)
        MsgBox "To: " & oAddr.Name & "<" & oAddr.Address & ">"
    Next
    
    arAddr = oMail.Cc
    For i = LBound(arAddr) To UBound(arAddr)
        Set oAddr = arAddr(i)
        MsgBox "Cc: " & oAddr.Name & "<" & oAddr.Address & ">"
    Next
End Sub

[Visual C++]
#include "eagetmailobj.tlh"
using namespace EAGetMailObjLib;

void ParseMailAddress()
{
    ::CoInitialize( NULL );
    try
    {
        IMailPtr oMail;
        oMail.CreateInstance( "EAGetMailObj.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 );

        _variant_t arAddr;
        arAddr = oMail->To;
        SAFEARRAY *psa = arAddr.parray;
        LONG LBound = 0, UBound = 0;

        SafeArrayGetLBound( psa, 1, &LBound );
        SafeArrayGetUBound( psa, 1, &UBound );
        for( LONG i = LBound; i <= UBound; i++ )
        {
            _variant_t vt;
            ::SafeArrayGetElement( psa, &i, &vt );
            vt.pdispVal->QueryInterface( __uuidof(IMailAddress), (void**)&oAddr );

            _tprintf( _T("To: %s<%s>\r\n"), (TCHAR*)oAddr->Name, (TCHAR*)oAddr->Address );
        }

        arAddr = oMail->Cc;
        psa = arAddr.parray;

        SafeArrayGetLBound( psa, 1, &LBound );
        SafeArrayGetUBound( psa, 1, &UBound );
        for( LONG i = LBound; i <= UBound; i++ )
        {
            _variant_t vt;
            ::SafeArrayGetElement( psa, &i, &vt );
            vt.pdispVal->QueryInterface( __uuidof(IMailAddress), (void**)&oAddr );

            _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();
}