从剪贴板上读取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"); } } } }
欢迎访问《许阳的红泥屋》
征诛志异,三让两家王朝;功同开辟,一桮万古江南。