Esempio n. 1
0
 /// <summary>
 /// Sends the mail message.
 /// </summary>
 private void _ShowMail(object ignore)
 {
     MAPIHelperInterop.MapiMessage message = new MAPIHelperInterop.MapiMessage();
     using (RecipientCollection.InteropRecipientCollection interopRecipients
                = _recipientCollection.GetInteropRepresentation())
     {
         message.Subject        = _subject;
         message.NoteText       = _body;
         message.Recipients     = interopRecipients.Handle;
         message.RecipientCount = _recipientCollection.Count;
         // Check if we need to add attachments
         if (_files.Count > 0)
         {
             // Add attachments
             message.Files = _AllocAttachments(out message.FileCount);
         }
         // Signal the creating thread (make the remaining code async)
         _manualResetEvent.Set();
         const int MAPI_DIALOG = 0x8;
         //const int MAPI_LOGON_UI = 0x1;
         const int SUCCESS_SUCCESS = 0;
         int       error           = MAPIHelperInterop.MAPISendMail(IntPtr.Zero, IntPtr.Zero, message, MAPI_DIALOG, 0);
         if (_files.Count > 0)
         {
             // Deallocate the files
             _DeallocFiles(message);
         }
         // Check for error
         if (error != SUCCESS_SUCCESS)
         {
             _LogErrorMapi(error);
         }
     }
 }
Esempio n. 2
0
    private void _ShowMail(object ignore)
    {
        _logger.Info("Showing mail client");
        var message = new MapiHelperInterop.MapiMessage();

        using (RecipientCollection.InteropRecipientCollection interopRecipients
                   = _recipientCollection.GetInteropRepresentation())
        {
            _logger.Info("Subject: " + _subject);
            message.Subject  = _subject;
            message.NoteText = _body;

            message.Recipients     = interopRecipients.Handle;
            message.RecipientCount = _recipientCollection.Count;

            _logger.Info("Adding {0} files ", _files.Count);
            // Check if we need to add attachments
            if (_files.Count > 0)
            {
                // Add attachments
                message.Files = _AllocAttachments(out message.FileCount);
            }

            // Signal the creating thread (make the remaining code async)
            _manualResetEvent.Set();

            const int MAPI_DIALOG = 0x8;
            //const int MAPI_LOGON_UI = 0x1;
            //const int SUCCESS_SUCCESS = 0;
            _logger.Info("Starting MAPI call");

            try
            {
                int error = MapiHelperInterop.MAPISendMail(IntPtr.Zero, IntPtr.Zero, message, MAPI_DIALOG, 0);

                _logger.Info("MAPI result was: " + error);

                if (_files.Count > 0)
                {
                    // Deallocate the files
                    _DeallocFiles(message);
                }

                _LogErrorMapi(error);
            }
            catch (InvalidOperationException ex)
            {
                _logger.Error(ex);
                throw new MapiException("The MAPI call could not be completed due an InvalidOperationException.", ex);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }
        }
        _logger.Info("Done with MAPI");
    }