Subversion Repositories vs2008

Rev

Rev 9 | Blame | Compare with Previous | Last modification | View Log | RSS feed

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using System.Reflection;
using Outlook = Microsoft.Office.Interop.Outlook;
using Redemption;

namespace OutlookTest {
  class Program {
    /// <summar>y
    /// The main entry point for the application.
    /// </summary>
    private Outlook.Application app = null;

    public Program() {
      app = new Outlook.ApplicationClass();
    }

    private string getMimeType(string fileName) {
      string mimeType = "application/unknown";
      string ext = System.IO.Path.GetExtension(fileName).ToLower();
      Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
      if (regKey != null && regKey.GetValue("Content Type") != null) {
        mimeType = regKey.GetValue("Content Type").ToString();
      }

      return mimeType;
    }

    [STAThread]
    static void Main() {
      //Application.EnableVisualStyles();
      //Application.SetCompatibleTextRenderingDefault(false);
      //Application.Run(new Form1());
      Program p = new Program();

     
      try {
        System.Console.WriteLine("Got new app instance");
        Outlook.NameSpace NS = p.app.GetNamespace("MAPI");
        Outlook.MAPIFolder inbox = NS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

        //Outlook.MailItem t = (Outlook.MailItem)inbox.Items[1];
        Outlook.MailItem t = null;
        foreach (object obj in inbox.Items) {
          Outlook.MailItem t1 = obj as Outlook.MailItem;
          
          if (t1 == null) continue;

          if (t1.Subject == "Test 2") {
            t = t1;
            break;
          }
          //System.Console.WriteLine(t.Subject + " -- " + t.BodyFormat);
        }
        
        foreach(Outlook.Recipient r in t.Recipients) {
          System.Console.WriteLine("Address: "+r.Address);
          System.Console.WriteLine("Name: " + r.Name);
          System.Console.WriteLine("");
        }
       
        System.Console.WriteLine("CC: "+t.CC);
        System.Console.WriteLine("Received: {0}", t.ReceivedTime.ToString());
        System.Console.WriteLine("Sent On: "+t.SentOn);
        System.Console.WriteLine("To: "+t.To);
        System.Console.WriteLine("Sender Email: "+t.SenderEmailAddress);
        System.Console.WriteLine("Sender Email: " + t.SenderEmailAddress.ToString());
        System.Console.WriteLine("Sender Name: " + t.SenderName);
        System.Console.WriteLine("Recipients: "+t.Recipients.ToString());
        System.Console.WriteLine("Subject: " + t.Subject);

        foreach (Outlook.Attachment a in t.Attachments) {
          
          if (a.Type == Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem) {
            System.Console.WriteLine("");
            
            //Type tt = a.GetType();
            //string messageClass = tt.InvokeMember("MessasgeClass", BindingFlags.Public | BindingFlags.GetField | BindingFlags.GetProperty, null, a, new object[] { }).ToString();
            //Console.WriteLine("\tType: " + messageClass);
            
            System.Console.WriteLine("");
            System.Console.WriteLine("Type embed: "+a.Type);
            System.Console.WriteLine("Get Type: " + a.GetType());
            System.Console.WriteLine("Class: " + a.Class);
            System.Console.WriteLine("BlockLevel: " + a.BlockLevel);
            System.Console.WriteLine("Application: " + a.Application);
            System.Console.WriteLine("Parent: " + a.Parent);
            System.Console.WriteLine("PropertyAccessor: " + a.PropertyAccessor);
            
/*
            Outlook.TaskRequestUpdateItem item;
            ....
            Outlook.Attachments atts = item.Attachments;
            Outlook.Attachment att = atts[1];

            att.SaveAsFile("F:\\111.oft");
            Outlook.TaskItem task =
            (Outlook.TaskItem)ThisApplication.OlApp.CreateItemFromTemplate("F:\\111.oft", Type.Missing);
 */

            
            //p.app.CreateItemFromTemplate("t.msg",Type.Missing);
            //p.app.Cre

            //System.Console.WriteLine("CC: " + t2.CC);
            //System.Console.WriteLine("Sent On: " + t2.SentOn);
            //System.Console.WriteLine("To: " + t2.To);
            //System.Console.WriteLine("Sender Email: " + t2.SenderEmailAddress);
            //System.Console.WriteLine("Sender Name: " + t2.SenderName);
            //System.Console.WriteLine("Recipients: " + t2.Recipients.ToString());
            //System.Console.WriteLine("Subject: " + t2.Subject);
            System.Console.WriteLine("");
          }
          System.Console.WriteLine("Application: " + p.getMimeType(a.FileName));
          System.Console.WriteLine("DisplayName: " + a.DisplayName);
          System.Console.WriteLine("Filename: " + a.FileName);

          System.Console.WriteLine("Index: " + a.Index);
          System.Console.WriteLine("Position: " + a.Position);
          System.Console.WriteLine("Size: " + a.Size);
          System.Console.WriteLine("Type: " + a.Type);
          System.Console.WriteLine("");
        }
        /*
        foreach (Outlook.MailItem t in inbox.Items) {
          System.Console.WriteLine(t.Subject+ " -- "+t.BodyFormat);
        }
        */
      } catch (Exception ex) {
        System.Console.WriteLine(ex.ToString());
      }

      Console.ReadLine();
    }
  }
}