读书人

从剪贴板下读取Outlook中的邮件

发布时间: 2012-10-11 10:16:10 作者: rapoo

从剪贴板上读取Outlook中的邮件

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using System.Diagnostics;using Outlook = Microsoft.Office.Interop.Outlook;using System.Runtime.InteropServices;namespace WindowsFormsApplication1{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            IDataObject iData = Clipboard.GetDataObject();            MemoryStream ms = (MemoryStream)iData.GetData("Csv");            if (ms != null)            {                byte[] buffer = new byte[ms.Length];                ms.Read(buffer, 0, buffer.Length);                string EntryId = System.Text.Encoding.Unicode.GetString(buffer);                Process[] ps = Process.GetProcessesByName("OUTLOOK");                Outlook.Application olApp = null;                if (ps.Length > 0)                {                    olApp = (Outlook.Application)Marshal.GetActiveObject("Outlook.Application");                }                else                {                    olApp = new Outlook.Application();                }                var item = olApp.Session.GetItemFromID(EntryId);                item.SaveAs("test.msg", Outlook.OlSaveAsType.olMSGUnicode);            }            else            {                MessageBox.Show("NO");            }        }    }}



欢迎访问《许阳的红泥屋》

欢迎访问《许阳的红泥屋》

读书人网 >其他相关

热点推荐