Beispiel #1
0
        /**
         *
         * Need to forward email as an attachment.  Why?  Forwarding as an
         * attachment is a way to share the email body in exactly the form
         * you received it. This makes it easier for the recipient of your
         * forward to reply to the original sender and it preserves some
         * message details that can otherwise be lost — useful to help
         * troubleshooting email problems, for example.
         *
         */

        private void forwardMailAsAttachement(Microsoft.Office.Interop.Outlook.MailItem mail)
        {
            if (mail == null)
            {
                MessageBox.Show("No EMAIL to forward!");
            }
            else
            {
                string forwardRecipient = form.PhishingEmailAddress;
                string forwardSubject   = form.PhishingEmailSubject;

                // Create newMail object from original mail object's Forward() call...
                Microsoft.Office.Interop.Outlook.MailItem newMail = mail.Forward();

                log.Debug(
                    "Forwarding Email to  EMAIL to: Receipient: " + forwardRecipient +
                    "; Sender: " + mail.SenderName + "; Subject: " +
                    mail.Subject);

                newMail.Subject = forwardSubject;

                newMail.Recipients.Add(forwardRecipient);

                // Need to clear out email Body...
                newMail.Body = buildPhishingEmailBody(mail);

                // Need to attach the currMail item...
                newMail.Attachments.Add(
                    mail, Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem);

                // NO LONGER DISPLAYING THE EMAIL - BUT LEAVING HERE FOR NOW!
                // Display the new eMail and pass in TRUE to make it modal.  This
                // will require the user to have to respond to the new email that
                // has popped up onto the user's screen; either modify/not modify
                // and send it, or cancel it.  If the user cancel's it, the
                // application will treat that as a cancel of the Phishing
                // Reporting operation, and the email will neither be forwarded
                // nor moved.
                //newMail.Display(true);

                // Based on feedback from JV, he would rather just send the
                // forwarded email!
                // Send the forwarded email...
                newMail.Send();

                // No need to do this logic now since we are just sending it and
                // no longer displaying the forwarded email.  But leaving it here
                // for now.  We can clean this code up after we have source code
                // control.
                // Need to do something hokey here...capture exception to determine
                // if the mail was sent successfully...
                //try
                //{
                //   // Need to return if the email was cancelled.  Otherwise, we
                //   // will get an exception with the message "The item is moved or
                //   // deleted".
                //   mailSent = newMail.Sent;
                //}
                //catch (System.Exception ex)
                //{
                //   // The only way to tell if we got the expected exception we are
                //   // looking for is to verify the contents of the exception
                //   // message contains the "explanation" we expect.
                //   if (ex.Message.ToUpper().Contains(
                //      "THE ITEM HAS BEEN MOVED OR DELETED") == true)
                //   {
                //      mailSent = true;
                //   }
                //   else
                //   {
                //      // If the exception is another exception, just output an
                //      // error message!
                //      MessageBox.Show(
                //         "Exception encountered - Please report to IT!  " +
                //         "Exception: " +
                //         ex.Message);
                //   }
                //}
            }
        }