Пример #1
0
        /// <summary>
        /// Processes existing files in the destination being monitored.
        /// </summary>
        private void ProcessExisting()
        {
            Console.WriteLine("Processing existing emails for '{0}'.".FormatWith(_emailAddress));
            Collection <EmailMessage> allmessages       = null;
            Collection <EmailMessage> processedMessages = new Collection <EmailMessage>();

            try
            {
                allmessages = _controller.RetrieveMessages(EmailFolder.Inbox);
            }
            catch (EmailServerException ex)
            {
                //Something's up with the Email server.
                TraceFactory.Logger.Error(ex);
                return;
            }

            // Process each email, and note which ones are successful
            foreach (EmailMessage message in allmessages)
            {
                bool success = ProcessMessage(message);
                if (success)
                {
                    processedMessages.Add(message);
                }
            }

            // Remove all the successful messages from the server
            _controller.Delete(processedMessages);
        }
Пример #2
0
        public void CheckForEmailResponse()
        {
            try
            {
                StringBuilder logText = new StringBuilder();

                ExecutionServices.SystemTrace.LogDebug("Retrieving Email Responses.");
                // Look through all the received mail to find one with "ePrint" in subject line
                foreach (EmailMessage message in _emailController.RetrieveMessages(EmailFolder.Inbox))
                {
                    if (message.Subject.Contains("ePrint", StringComparison.InvariantCultureIgnoreCase))
                    {
                        logText.Clear();
                        LogHeaders(message, ref logText);

                        if (HasPrinted(message, ref logText))
                        {
                            // The document has been printed.
                            _emailController.Delete(message);
                        }
                        else if (IsProcessing(message, ref logText))
                        {
                            // The document was received
                            _emailController.Delete(message);
                        }
                        else if (IsPartiallyReady(message, ref logText))
                        {
                            // "Partially Ready" is an error condition.
                            _emailController.Delete(message);
                        }
                        else // Unrecognized text in the body of the message.
                        {
                            logText.Append(Environment.NewLine);
                            logText.AppendLine("Print job failed.");
                            logText.Append(message.Subject).Append("  ");
                            logText.Append(CleanUpHtml(message.Body));
                        }
                    }
                    else // Unrecognized email message.
                    {
                        logText.AppendLine("Non-ePrint related email received: ");
                        logText.Append(message.Subject);
                        logText.Append("BODY: ").Append(CleanUpHtml(message.Body));
                    }

                    logText.AppendLine();
                    OnEmailResponseReceived(logText.ToString());
                }
            }
            catch (Exception ex)
            {
                CleanEmailFolders();
                ExecutionServices.SystemTrace.LogError(ex);
            }
        }
Пример #3
0
        private void ReceiveEmail(string recipient)
        {
            Collection <EmailMessage> messages = _emailController.RetrieveMessages(EmailFolder.Inbox);

            foreach (EmailMessage email in messages)
            {
                _operationLog.Append("Received email from: ").Append(email.FromAddress.Address);
                _operationLog.Append(" to: ").AppendLine(recipient);
            }

            _operationLog.Append("Clearing out Inbox for ").AppendLine(recipient);
            _emailController.Clear(EmailFolder.Inbox);
        }
Пример #4
0
 /// <summary>
 /// Get the Inbox messages.
 /// </summary>
 /// <returns>List of Email messages from the Inbox.</returns>
 private Collection <EmailMessage> GetInboxItems()
 {
     try
     {
         Collection <EmailMessage> messages = _emailController.RetrieveMessages(EmailFolder.Inbox);
         // Take this opportunity to clean out the inbox.
         // This is being done by the EmailMonitor
         //_emailController.Delete(messages);
         //_emailController.Clean(EmailFolder.SentItems);
         return(messages);
     }
     catch (Exception ex)
     {
         ExecutionServices.SystemTrace.LogError(ex);
         throw;
     }
 }