예제 #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);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Sends the mail message.
        /// </summary>
        private void _ShowMail(object deleteFilesOnExit)
        {
            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;
                int error = MAPIHelperInterop.MAPISendMail(IntPtr.Zero, IntPtr.Zero, message, MAPI_DIALOG, 0);

                if (_files.Count > 0)
                {
                    // Deallocate the files
                    _DeallocFiles(message);
                    if ((bool)deleteFilesOnExit)
                    {
                        foreach (string file in _files)
                        {
                            try {
                                if (File.Exists(file))
                                {
                                    LOG.Debug("Deleting file " + file);
                                    File.Delete(file);
                                }
                            } catch (Exception e) {
                                LOG.Error("Can't delete file " + file, e);
                            }
                        }
                    }
                }
                MAPI_CODES errorCode = (MAPI_CODES)Enum.ToObject(typeof(MAPI_CODES), error);

                // Check for error
                if (errorCode != MAPI_CODES.SUCCESS && errorCode != MAPI_CODES.USER_ABORT)
                {
                    _LogErrorMapi(errorCode);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Sends the mail message.
        /// </summary>
        private void _ShowMail()
        {
            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;
                int error = MAPIHelperInterop.MAPISendMail(IntPtr.Zero, IntPtr.Zero, message, MAPI_DIALOG, 0);

                if (_files.Count > 0)
                {
                    // Deallocate the files
                    _DeallocFiles(message);
                }
                MAPI_CODES errorCode = (MAPI_CODES)Enum.ToObject(typeof(MAPI_CODES), error);

                // Check for error
                if (errorCode != MAPI_CODES.SUCCESS && errorCode != MAPI_CODES.USER_ABORT)
                {
                    string errorText = GetMapiError(errorCode);
                    LOG.Error("Error sending MAPI Email. Error: " + errorText + " (code = " + errorCode + ").");
                    MessageBox.Show(errorText, "Mail (MAPI) destination", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    // Recover from bad settings, show again
                    if (errorCode == MAPI_CODES.INVALID_RECIPS)
                    {
                        _recipientCollection = new RecipientCollection();
                        _ShowMail();
                    }
                }
            }
        }
예제 #4
0
 /// <summary>
 /// Deallocates the files in a message.
 /// </summary>
 /// <param name="message">The message to deallocate the files from.</param>
 private void _DeallocFiles(MAPIHelperInterop.MapiMessage message)
 {
     if (message.Files != IntPtr.Zero)
     {
         Type fileDescType = typeof(MapiFileDescriptor);
         int  fsize        = Marshal.SizeOf(fileDescType);
         // Get the ptr to the files
         int runptr = (int)message.Files;
         // Release each file
         for (int i = 0; i < message.FileCount; i++)
         {
             Marshal.DestroyStructure((IntPtr)runptr, fileDescType);
             runptr += fsize;
         }
         // Release the file
         Marshal.FreeHGlobal(message.Files);
     }
 }
예제 #5
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);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Sends the mail message.
        /// </summary>
        private void showMail()
        {
            var message = new MAPIHelperInterop.MapiMessage();

            using (var 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;

                var error = MAPIHelperInterop.MAPISendMail(IntPtr.Zero, IntPtr.Zero, message, MAPI_DIALOG, 0);

                if (_Files.Count > 0)
                {
                    // Deallocate the files
                    deallocFiles(message);
                }

                // Check for error
                string errorDescription = getErrorDescription(error);
                switch ((MAPIErrorCode)error)
                {
                case MAPIErrorCode.MAPI_SUCCESS:
                case MAPIErrorCode.MAPI_USER_ABORT:
                    //do nothing
                    break;

                case MAPIErrorCode.MAPI_E_NO_MAIL_CLIENT:
                {
                    //todo - add description to lang file in next version
                    var msg = PNLang.Instance.GetMessageText("mail_error", "MAPI error:") + '\n' +
                              error.ToString(CultureInfo.InvariantCulture) + '\n' + "No default mail client installed";
                    Task.Factory.StartNew(
                        () =>
                        {
                            PNMessageBox.Show(msg, PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Error);
                        },
                        CancellationToken.None,
                        TaskCreationOptions.None,
                        _TaskScheduler);
                    break;
                }

                default:
                {
                    var msg = PNLang.Instance.GetMessageText("mail_error", "MAPI error:") + '\n' +
                              error.ToString(CultureInfo.InvariantCulture) + '\n' + errorDescription;
                    Task.Factory.StartNew(
                        () =>
                        {
                            PNMessageBox.Show(msg, PNStrings.PROG_NAME, MessageBoxButton.OK, MessageBoxImage.Error);
                        },
                        CancellationToken.None,
                        TaskCreationOptions.None,
                        _TaskScheduler);
                    break;
                }
                }
            }
        }
예제 #7
0
파일: MapiMailMessage.cs 프로젝트: x893/WDS
 private void _ShowMail(object ignore)
 {
     MAPIHelperInterop.MapiMessage message = new MAPIHelperInterop.MapiMessage();
     using (RecipientCollection.InteropRecipientCollection recipients = this._recipientCollection.GetInteropRepresentation())
     {
         message.Subject = this._subject;
         message.NoteText = this._body;
         message.Recipients = recipients.Handle;
         message.RecipientCount = this._recipientCollection.Count;
         if (this._files.Count > 0)
         {
             message.Files = this._AllocAttachments(out message.FileCount);
         }
         this._manualResetEvent.Set();
         int errorCode = MAPIHelperInterop.MAPISendMail(IntPtr.Zero, IntPtr.Zero, message, 8, 0);
         if (this._MAPIResultEvent != null)
         {
             this._MAPIResultEvent(errorCode);
         }
         if (this._files.Count > 0)
         {
             this._DeallocFiles(message);
         }
     }
 }
예제 #8
0
        /// <summary>
        /// Sends the mail message.
        /// </summary>
        private void _ShowMail(object deleteFilesOnExit)
        {
            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;
                int error = MAPIHelperInterop.MAPISendMail(IntPtr.Zero, IntPtr.Zero, message, MAPI_DIALOG, 0);

                if (_files.Count > 0) {
                    // Deallocate the files
                    _DeallocFiles(message);
                    if ((bool)deleteFilesOnExit) {
                        foreach(string file in _files) {
                            try {
                                if (File.Exists(file)) {
                                    LOG.Debug("Deleting file " + file);
                                    File.Delete(file);
                                }
                            } catch (Exception e) {
                                LOG.Error("Can't delete file " + file, e);
                            }
                        }
                    }
                }
                MAPI_CODES errorCode = (MAPI_CODES)Enum.ToObject(typeof(MAPI_CODES), error);

                // Check for error
                if (errorCode != MAPI_CODES.SUCCESS && errorCode != MAPI_CODES.USER_ABORT) {
                    _LogErrorMapi(errorCode);
                }
            }
        }
예제 #9
0
		/// <summary>
		/// Sends the mail message.
		/// </summary>
		private void _ShowMail() {
			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;
				int error = MAPIHelperInterop.MAPISendMail(IntPtr.Zero, IntPtr.Zero, message, MAPI_DIALOG, 0);

				if (_files.Count > 0) {
					// Deallocate the files
					_DeallocFiles(message);
				}
				MAPI_CODES errorCode = (MAPI_CODES)Enum.ToObject(typeof(MAPI_CODES), error);

				// Check for error
				if (errorCode != MAPI_CODES.SUCCESS && errorCode != MAPI_CODES.USER_ABORT) {
					string errorText = GetMapiError(errorCode);
					LOG.Error("Error sending MAPI Email. Error: " + errorText + " (code = " + errorCode + ").");
					MessageBox.Show(errorText, "Mail (MAPI) destination", MessageBoxButtons.OK, MessageBoxIcon.Error);
					// Recover from bad settings, show again
					if (errorCode == MAPI_CODES.INVALID_RECIPS) {
						_recipientCollection = new RecipientCollection();
						_ShowMail();
					}
				}
			}
		}