Esempio n. 1
0
        /// <summary>
        /// This method replies email according to the parameters
        /// </summary>
        /// <param name="operation">parameters for MailReply</param>
        /// <returns>true if processed successfully, false otherwise</returns>
        private bool MailReply(MailSimOperationsMailReply operation)
        {
            var parsedOp = ParseOperation(operation, operation.Folder, operation.MailSubjectToReply);

            return(parsedOp.Iterate((indexToReply, mails) =>
            {
                IMailItem mailToReply = mails[indexToReply].Reply(operation.ReplyAll);

                Log.Out(Log.Severity.Info, operation.OperationName, "Subject: {0}", mailToReply.Subject);

                mailToReply.Body = BuildBody(operation.ReplyBody) + mailToReply.Body;
                Log.Out(Log.Severity.Info, operation.OperationName, "Body: {0}", mailToReply.Body);

                // process the attachment
                AddAttachments(mailToReply, operation);

                mailToReply.Send();
                return true;
            }));
        }
Esempio n. 2
0
        /// <summary>
        /// This method replies email according to the parameters
        /// </summary>
        /// <param name="operation">parameters for MailReply</param>
        /// <returns>true if processed successfully, false otherwise</returns>
        private bool MailReply(MailSimOperationsMailReply operation)
        {
            var parsedOp = ParseOperation(operation, operation.Folder, operation.MailSubjectToReply);

            return parsedOp.Iterate((indexToReply, mails) =>
            {
                IMailItem mailToReply = mails[indexToReply].Reply(operation.ReplyAll);

                Log.Out(Log.Severity.Info, operation.OperationName, "Subject: {0}", mailToReply.Subject);

                mailToReply.Body = BuildBody(operation.ReplyBody) + mailToReply.Body;
                Log.Out(Log.Severity.Info, operation.OperationName, "Body: {0}", mailToReply.Body);

                // process the attachment
                AddAttachments(mailToReply, operation);

                mailToReply.Send();
                return true;
            });
        }
        /// <summary>
        /// This method replies email according to the parameters
        /// </summary>
        /// <param name="operation">parameters for MailReply</param>
        /// <returns>true if processed successfully, false otherwise</returns>
        private bool MailReply(MailSimOperationsMailReply operation)
        {
            int iterations = GetIterationCount(operation.Count);
            bool random = false;

            try
            {
                // retrieves mails from Outlook
                var mails = GetMails(operation.OperationName, operation.Folder, operation.MailSubjectToReply).ToList();
                if (mails.Any() == false)
                {
                    Log.Out(Log.Severity.Error, operation.OperationName, "Skipping MailReply");
                    return false;
                }

                // randomly generate the number of emails to reply
                if (iterations == 0)
                {
                    random = true;
                    iterations = randomNum.Next(1, mails.Count + 1);
                    Log.Out(Log.Severity.Info, operation.OperationName, "Randomly replying {0} emails", iterations);
                }

                // we need to make sure we are not replying more than what we have in the mailbox
                if (iterations > mails.Count)
                {
                    Log.Out(Log.Severity.Warning, operation.OperationName,
                        "Only {1} email(s) are in the folder, so the number of emails to reply is adjusted from {0} to {1}",
                        iterations, mails.Count);
                    iterations = mails.Count;
                }

                for (int count = 1; count <= iterations; count++)
                {
                    Log.Out(Log.Severity.Info, operation.OperationName, "Starting iteration {0}", count);

                    List<string> attachments = GetAttachments(operation.OperationName, operation.Attachments);

                    // just reply the email in order if random is not selected,
                    // otherwise randomly pick the mail to reply
                    int indexToReply = random ? randomNum.Next(0, mails.Count) : count - 1;
                    IMailItem mailToReply = mails[indexToReply].Reply(operation.ReplyAll);

                    Log.Out(Log.Severity.Info, operation.OperationName, "Subject: {0}", mailToReply.Subject);

                    mailToReply.Body = System.DateTime.Now.ToString() + " - " +
                        ((string.IsNullOrEmpty(operation.ReplyBody)) ? DefaultBody : operation.ReplyBody) +
                        mailToReply.Body;
                    Log.Out(Log.Severity.Info, operation.OperationName, "Body: {0}", mailToReply.Body);

                    // process the attachment
                    foreach (string attmt in attachments)
                    {
                        Log.Out(Log.Severity.Info, operation.OperationName, "Attachment: {0}", attmt);
                        mailToReply.AddAttachment(attmt);
                    }

                    mailToReply.Send();

                    SleepOrStop(operation.OperationName, operation.Sleep);

                    Log.Out(Log.Severity.Info, operation.OperationName, "Finished iteration {0}", count);
                }
            }
            catch (Exception ex)
            {
                Log.Out(Log.Severity.Error, operation.OperationName, "Exception encountered\n" + ex);
                return false;
            }

            return true;
        }