home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 217 / DPCS0306DVD.ISO / Toolkit / Internet / FileZilla / Server / FileZilla_Server-0.9.11.exe / source / misc / MailMsg.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-04-04  |  7.3 KB  |  295 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Module: MailMsg.h
  4. //
  5. //    Desc: This class encapsulates the MAPI and CMC mail functions.
  6. //
  7. // Copyright (c) 2003 Michael Carruth
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10.  
  11. #ifndef _MAILMSG_H_
  12. #define _MAILMSG_H_
  13.  
  14. #if _MSC_VER >= 1000
  15. #pragma once
  16. #endif // _MSC_VER >= 1000
  17.  
  18. #include <xcmc.h>          // CMC function defs
  19. #include <mapi.h>          // MAPI function defs
  20.  
  21. #ifndef TStrStrMap
  22. #include <map>
  23.  
  24. typedef std::map<CStdString, CStdString> TStrStrMap;
  25. #endif // !defined TStrStrMap
  26.  
  27. //
  28. // Define CMC entry points
  29. //
  30. typedef CMC_return_code (FAR PASCAL *LPCMCLOGON) \
  31.    (CMC_string, CMC_string, CMC_string, CMC_object_identifier, \
  32.    CMC_ui_id, CMC_uint16, CMC_flags, CMC_session_id FAR*, \
  33.    CMC_extension FAR*);
  34.  
  35. typedef CMC_return_code (FAR PASCAL *LPCMCSEND) \
  36.    (CMC_session_id, CMC_message FAR*, CMC_flags, \
  37.    CMC_ui_id, CMC_extension FAR*);
  38.  
  39. typedef CMC_return_code (FAR PASCAL *LPCMCLOGOFF) \
  40.    (CMC_session_id, CMC_ui_id, CMC_flags, CMC_extension FAR*);
  41.  
  42. typedef CMC_return_code (FAR PASCAL *LPCMCQUERY) \
  43.    (CMC_session_id, CMC_enum, CMC_buffer, CMC_extension FAR*);
  44.  
  45.  
  46. ////////////////////////////// Class Definitions /////////////////////////////
  47.  
  48. // ===========================================================================
  49. // CMailMsg
  50. // 
  51. // See the module comment at top of file.
  52. //
  53. class CMailMsg  
  54. {
  55. public:
  56.     CMailMsg();
  57.     virtual ~CMailMsg();
  58.  
  59.    //-----------------------------------------------------------------------------
  60.    // SetTo
  61.    //    Sets the Email:To address
  62.    //
  63.    // Parameters
  64.    //    sAddress    Address
  65.    //    sName       Optional name
  66.    //
  67.    // Return Values
  68.    //    CMailMsg reference
  69.    //
  70.    // Remarks
  71.    //    Only one To address can be set.  If called more than once
  72.    //    the last address will be used.
  73.    //
  74.    CMailMsg& 
  75.    SetTo(
  76.       CStdString sAddress, 
  77.       CStdString sName = _T("")
  78.       );
  79.  
  80.    //-----------------------------------------------------------------------------
  81.    // SetCc
  82.    //    Sets the Email:Cc address
  83.    //
  84.    // Parameters
  85.    //    sAddress    Address
  86.    //    sName       Optional name
  87.    //
  88.    // Return Values
  89.    //    CMailMsg reference
  90.    //
  91.    // Remarks
  92.    //    Multiple Cc addresses can be set.
  93.    //
  94.    CMailMsg& 
  95.    SetCc(
  96.       CStdString sAddress, 
  97.       CStdString sName = _T("")
  98.       );
  99.  
  100.    //-----------------------------------------------------------------------------
  101.    // SetBc
  102.    //    Sets the Email:Bcc address
  103.    //
  104.    // Parameters
  105.    //    sAddress    Address
  106.    //    sName       Optional name
  107.    //
  108.    // Return Values
  109.    //    CMailMsg reference
  110.    //
  111.    // Remarks
  112.    //    Multiple Bcc addresses can be set.
  113.    //
  114.    CMailMsg& 
  115.    SetBc(
  116.       CStdString sAddress, 
  117.       CStdString sName = _T("")
  118.       );
  119.  
  120.    //-----------------------------------------------------------------------------
  121.    // SetFrom
  122.    //    Sets the Email:From address
  123.    //
  124.    // Parameters
  125.    //    sAddress    Address
  126.    //    sName       Optional name
  127.    //
  128.    // Return Values
  129.    //    CMailMsg reference
  130.    //
  131.    // Remarks
  132.    //    Only one From address can be set.  If called more than once
  133.    //    the last address will be used.
  134.    //
  135.    CMailMsg& 
  136.    SetFrom(
  137.       CStdString sAddress, 
  138.       CStdString sName = _T("")
  139.       );
  140.  
  141.    //-----------------------------------------------------------------------------
  142.    // SetSubect
  143.    //    Sets the Email:Subject
  144.    //
  145.    // Parameters
  146.    //    sSubject    Subject
  147.    //
  148.    // Return Values
  149.    //    CMailMsg reference
  150.    //
  151.    // Remarks
  152.    //    none
  153.    //
  154.    CMailMsg& 
  155.    SetSubject(
  156.       CStdString sSubject
  157.       ) {m_sSubject = sSubject; return *this;};
  158.  
  159.    //-----------------------------------------------------------------------------
  160.    // SetMessage
  161.    //    Sets the Email message body
  162.    //
  163.    // Parameters
  164.    //    sMessage    Message body
  165.    //
  166.    // Return Values
  167.    //    CMailMsg reference
  168.    //
  169.    // Remarks
  170.    //    none
  171.    //
  172.    CMailMsg& 
  173.    SetMessage(
  174.       CStdString sMessage
  175.       ) {m_sMessage = sMessage; return *this;};
  176.  
  177.    //-----------------------------------------------------------------------------
  178.    // AddAttachment
  179.    //    Attaches a file to the email
  180.    //
  181.    // Parameters
  182.    //    sAttachment Fully qualified file name
  183.    //    sTitle      File display name
  184.    //
  185.    // Return Values
  186.    //    CMailMsg reference
  187.    //
  188.    // Remarks
  189.    //    none
  190.    //
  191.    CMailMsg& 
  192.    AddAttachment(
  193.       CStdString sAttachment, 
  194.       CStdString sTitle = _T("")
  195.       );
  196.  
  197.    //-----------------------------------------------------------------------------
  198.    // Send
  199.    //    Send the email.
  200.    //
  201.    // Parameters
  202.    //    none
  203.    //
  204.    // Return Values
  205.    //    TRUE if succesful
  206.    //
  207.    // Remarks
  208.    //    First simple MAPI is used if unsucessful CMC is used.
  209.    //
  210.    BOOL Send();
  211.  
  212. protected:
  213.  
  214.    //-----------------------------------------------------------------------------
  215.    // CMCSend
  216.    //    Send email using CMC functions.
  217.    //
  218.    // Parameters
  219.    //    none
  220.    //
  221.    // Return Values
  222.    //    TRUE if successful
  223.    //
  224.    // Remarks
  225.    //    none
  226.    //
  227.    BOOL CMCSend();
  228.  
  229.    //-----------------------------------------------------------------------------
  230.    // MAPISend
  231.    //    Send email using MAPI functions.
  232.    //
  233.    // Parameters
  234.    //    none
  235.    //
  236.    // Return Values
  237.    //    TRUE if successful
  238.    //
  239.    // Remarks
  240.    //    none
  241.    //
  242.    BOOL MAPISend();
  243.  
  244.    //-----------------------------------------------------------------------------
  245.    // Initialize
  246.    //    Initialize MAPI32.dll
  247.    //
  248.    // Parameters
  249.    //    none
  250.    //
  251.    // Return Values
  252.    //    TRUE if successful
  253.    //
  254.    // Remarks
  255.    //    none
  256.    //
  257.    BOOL Initialize();
  258.  
  259.    //-----------------------------------------------------------------------------
  260.    // Uninitialize
  261.    //    Uninitialize MAPI32.dll
  262.    //
  263.    // Parameters
  264.    //    none
  265.    //
  266.    // Return Values
  267.    //    void
  268.    //
  269.    // Remarks
  270.    //    none
  271.    //
  272.    void Uninitialize();
  273.  
  274.    TStrStrMap     m_from;                       // From <address,name>
  275.    TStrStrMap     m_to;                         // To <address,name>
  276.    TStrStrMap     m_cc;                         // Cc <address,name>
  277.    TStrStrMap     m_bcc;                        // Bcc <address,name>
  278.    TStrStrMap     m_attachments;                // Attachment <file,title>
  279.    CStdString     m_sSubject;                   // EMail subject
  280.    CStdString     m_sMessage;                   // EMail message
  281.  
  282.    HMODULE        m_hMapi;                      // Handle to MAPI32.DLL
  283.    LPCMCQUERY     m_lpCmcQueryConfiguration;    // Cmc func pointer
  284.    LPCMCLOGON     m_lpCmcLogon;                 // Cmc func pointer
  285.    LPCMCSEND        m_lpCmcSend;                  // Cmc func pointer
  286.    LPCMCLOGOFF        m_lpCmcLogoff;                // Cmc func pointer
  287.    LPMAPILOGON        m_lpMapiLogon;                // Mapi func pointer
  288.    LPMAPISENDMAIL m_lpMapiSendMail;             // Mapi func pointer
  289.    LPMAPILOGOFF   m_lpMapiLogoff;               // Mapi func pointer
  290.    
  291.    BOOL           m_bReady;                     // MAPI is loaded
  292. };
  293.  
  294. #endif    // #ifndef _MAILMSG_H_
  295.