CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    May 1999
    Posts
    17

    mail attachment extraction

    Hi all,

    I'm wrote a small application that use SOCKETs to communicate with POP3 server and download e-mails. All work O.K. if e-mail haven't attachment, but if e-mail have attachment I dont know how to extract them from mail.
    Does anybody can help me to find the way for extracting attachments from e-mail OR point me to source code OR link OR e-somebody's e-mail whose have experience with that.
    Is there a mail-list like this for SOCKET&mail ?

    Any help will be apperciated.

    Regards,
    Mileta Radenovic.



  2. #2
    Join Date
    May 1999
    Posts
    40

    Re: mail attachment extraction

    Hi,
    You can look for rfc1521 with description of MIME (Multipurpose Internet Mail Extensions). If You need an example in C++ E-mail me and I will send You a couple of files.
    Regards, IVS


  3. #3
    Join Date
    Apr 1999
    Posts
    23

    Re: mail attachment extraction

    Hi,

    You can actually use an external application like WinZip to extract MIME attachments.

    Chao


  4. #4
    Join Date
    May 1999
    Location
    Mass, USA.
    Posts
    103

    Re: mail attachment extraction

    Mileta,

    Check out http://codeguru.com/internet. In particular, see Wes' article http://codeguru.com/internet/mimemfc.shtml.

    /ravi



  5. #5
    Guest

    Re: mail attachment extraction

    Hi, i need the C++ source code which u mentioned.. Could you please send it to me.

    Thanks.
    [email protected]



  6. #6
    Guest

    MIME attachment extraction

    If you have some sample source code to extract MIME attachments from an e-mail could you please send them to me? [email protected]


  7. #7
    Join Date
    May 1999
    Posts
    68

    Re: mail attachment extraction

    hi,

    Please visit P.J. Naugthers Home page, goto network freeware and find a pop3 wrapper class (including MIMI support).

    URL : http://indigo.ie/~pjn/

    Hope this helps,

    -- Ron



  8. #8
    Join Date
    Apr 1999
    Location
    Pakistan
    Posts
    207

    Re: mail attachment extraction

    Hi,
    Is it possible for you to email me your code. I need some code which can do send email.
    Zulfi


  9. #9
    Join Date
    Apr 1999
    Location
    Pakistan
    Posts
    207

    Re: mail attachment extraction

    Hi,
    Is it possible for you to email me your code. I need some code which can do send email.
    [email protected]
    Zulfi


  10. #10
    Join Date
    May 1999
    Posts
    17

    Re: mail attachment extraction

    Hi Zulfi,

    You can try this :



    // ---------------------- SMTP global variables --------------------
    HANDLE hInst;
    HINSTANCE hlibMAPI = 0;

    LPMAPILOGON lpfnMAPILogon = NULL;
    LPMAPILOGOFF lpfnMAPILogoff = NULL;
    LPMAPISENDMAIL lpfnMAPISendMail = NULL;
    LPMAPISENDDOCUMENTS lpfnMAPISendDocuments = NULL;
    LPMAPIFINDNEXT lpfnMAPIFindNext = NULL;
    LPMAPIREADMAIL lpfnMAPIReadMail = NULL;
    LPMAPISAVEMAIL lpfnMAPISaveMail = NULL;
    LPMAPIDELETEMAIL lpfnMAPIDeleteMail = NULL;
    LPMAPIFREEBUFFER lpfnMAPIFreeBuffer = NULL;
    LPMAPIADDRESS lpfnMAPIAddress = NULL;
    LPMAPIDETAILS lpfnMAPIDetails = NULL;
    LPMAPIRESOLVENAME lpfnMAPIResolveName = NULL;


    static LHANDLE g_lhSession = 0L;

    #define szMAPIDLL "MAPI32.DLL"

    #define MAX_RECIPS 100
    #define MAX_ATTACHS 100

    #undef MAPILogon
    #undef MAPILogoff
    #undef MAPISendMail
    #undef MAPISendDocuments
    #undef MAPIFindNext
    #undef MAPIReadMail
    #undef MAPISaveMail
    #undef MAPIDeleteMail
    #undef MAPIFreeBuffer
    #undef MAPIAddress
    #undef MAPIDetails
    #undef MAPIResolveName
    #define MAPILogon (*lpfnMAPILogon)
    #define MAPILogoff (*lpfnMAPILogoff)
    #define MAPISendMail (*lpfnMAPISendMail)
    #define MAPISendDocuments (*lpfnMAPISendDocuments)
    #define MAPIFindNext (*lpfnMAPIFindNext)
    #define MAPIReadMail (*lpfnMAPIReadMail)
    #define MAPISaveMail (*lpfnMAPISaveMail)
    #define MAPIDeleteMail (*lpfnMAPIDeleteMail)
    #define MAPIFreeBuffer (*lpfnMAPIFreeBuffer)
    #define MAPIAddress (*lpfnMAPIAddress)
    #define MAPIDetails (*lpfnMAPIDetails)
    #define MAPIResolveName (*lpfnMAPIResolveName)



    // ---------------------- initialization ---------------------------

    void CTlgView::OnInitialUpdate()
    {
    CListView::OnInitialUpdate();

    // SMTP
    if ( !InitSimpleMAPI() )
    {
    MessageBox( "MAPI initialization failure", "Fatal error", MB_OK |
    MB_ICONSTOP );
    PostQuitMessage( 0 );
    return;
    }
    ULONG ulResult = MAPILogon( 0, NULL, NULL, MAPI_LOGON_UI |
    MAPI_NEW_SESSION, 0, &g_lhSession );
    if ( ulResult != SUCCESS_SUCCESS )
    {
    MessageBox( "Logon fail", "Logon error", MB_OK | MB_ICONSTOP );
    PostQuitMessage( 0 );
    return;
    }

    }





    bool CTlgView::InitSimpleMAPI( void )
    {
    if ( !SMAPIInstalled() ) return false;

    UINT uError = SetErrorMode( SEM_NOOPENFILEERRORBOX );
    hlibMAPI = LoadLibrary( szMAPIDLL );
    SetErrorMode( uError );

    if ( !hlibMAPI ) return false;

    if ( !(lpfnMAPILogon = (LPMAPILOGON)GetProcAddress(hlibMAPI,
    "MAPILogon")) ) return false;
    if ( !(lpfnMAPILogoff = (LPMAPILOGOFF)GetProcAddress(hlibMAPI,
    "MAPILogoff")) ) return false;
    if ( !(lpfnMAPISendMail = (LPMAPISENDMAIL)GetProcAddress(hlibMAPI,
    "MAPISendMail")) ) return false;
    if ( !(lpfnMAPISendDocuments =
    (LPMAPISENDDOCUMENTS)GetProcAddress(hlibMAPI, "MAPISendDocuments")) )
    return false;
    if ( !(lpfnMAPIFindNext = (LPMAPIFINDNEXT)GetProcAddress(hlibMAPI,
    "MAPIFindNext")) ) return false;
    if ( !(lpfnMAPIReadMail = (LPMAPIREADMAIL)GetProcAddress(hlibMAPI,
    "MAPIReadMail")) ) return false;
    if ( !(lpfnMAPISaveMail = (LPMAPISAVEMAIL)GetProcAddress(hlibMAPI,
    "MAPISaveMail")) ) return false;
    if ( !(lpfnMAPIDeleteMail = (LPMAPIDELETEMAIL)GetProcAddress(hlibMAPI,
    "MAPIDeleteMail")) ) return false;
    if ( !(lpfnMAPIFreeBuffer = (LPMAPIFREEBUFFER)GetProcAddress(hlibMAPI,
    "MAPIFreeBuffer")) ) return false;
    if ( !(lpfnMAPIAddress = (LPMAPIADDRESS)GetProcAddress(hlibMAPI,
    "MAPIAddress")) ) return false;
    if ( !(lpfnMAPIDetails = (LPMAPIDETAILS)GetProcAddress(hlibMAPI,
    "MAPIDetails")) ) return false;
    if ( !(lpfnMAPIResolveName = (LPMAPIRESOLVENAME)GetProcAddress(hlibMAPI,
    "MAPIResolveName")) ) return false;

    return true;
    }



    bool CTlgView::SMAPIInstalled( void )
    {
    LONG lr;
    HKEY hkWMS;

    #define MAPIVSize 8
    char szMAPIValue[MAPIVSize];
    DWORD dwType;
    DWORD cbMAPIValue = MAPIVSize;

    lr = RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows
    Messaging Subsystem", 0, KEY_READ, &hkWMS );
    if ( ERROR_SUCCESS == lr )
    {
    lr = RegQueryValueEx( hkWMS, "MAPI", 0, &dwType, (unsigned char
    *)szMAPIValue, &cbMAPIValue );
    RegCloseKey( hkWMS );
    if ( ERROR_SUCCESS == lr )
    {
    ASSERT( dwType == REG_SZ );
    if ( lstrcmp(szMAPIValue, "1") == 0 ) return true;
    }
    }
    return false;
    }





    // ------------------- sending ---------------------------

    bool CTlgView::Send( CString strTo, CString strSubj, CString strText )
    {
    MapiRecipDesc to[MAX_RECIPS], *temp[MAX_RECIPS];
    int nToCnt = 0;
    ULONG err;

    if ( strTo.IsEmpty() )
    {
    MessageBox( "TO : missing", "address fail", MB_OK | MB_ICONSTOP );
    return false;
    }

    LPTSTR str_to = (LPTSTR)(LPCTSTR)strTo;
    LPTSTR addr = strtok( str_to, ";\n," );
    while ( addr )
    {
    err = MAPIResolveName( g_lhSession, 0L, addr, MAPI_DIALOG, 0L,
    &temp[nToCnt] );
    if ( err != SUCCESS_SUCCESS ) return false;
    to[nToCnt].ulReserved = 0L;
    to[nToCnt].ulRecipClass = MAPI_TO;
    to[nToCnt].lpszName = temp[nToCnt]->lpszName;
    to[nToCnt].lpszAddress = temp[nToCnt]->lpszAddress;
    to[nToCnt].ulEIDSize = temp[nToCnt]->ulEIDSize;
    to[nToCnt].lpEntryID = temp[nToCnt]->lpEntryID;
    ++nToCnt;

    addr = strtok( NULL, ";\n," );
    }

    MapiMessage message;
    message.ulReserved = 0L;
    message.lpOriginator = NULL;
    message.nRecipCount = nToCnt;
    message.lpRecips = to;
    message.nFileCount = 0; // nAttCnt;
    message.lpFiles = NULL; // attachment;
    message.flFlags = 0;
    message.lpszConversationID = NULL;
    message.lpszDateReceived = NULL;
    message.lpszSubject = (LPTSTR)(LPCTSTR)strSubj;
    message.lpszMessageType = NULL;
    message.lpszNoteText = (LPTSTR)(LPCTSTR)strChiperText;

    err = MAPISendMail( g_lhSession, 0L, &message, 0L, 0L );
    for ( int i = 0; i < nToCnt; i++ ) MAPIFreeBuffer( temp[i] );

    return ( err == SUCCESS_SUCCESS );
    }








    Hope this help :
    Mileta.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured