Send all email data to a service from an outlook addin
我是Office Addins的新手。 我是一名MVC程序员,但这个项目已被我抛弃,因为没人愿意这样做。 我需要创建一个Outlook外挂程序,它将所有电子邮件数据转发到服务,在该服务中招聘系统可以跟踪通信。
我在用
1 | Application.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(saveEmail); |
然后,我将电子邮件投射到Outlook.MailItem中。 问题是我看不到获取电子邮件地址的方式。 它给我的就是人民的名字。 我想念什么吗?
到目前为止,我能想到的最佳解决方案是将msg保存为.msg文件。 将其转发到我的服务,然后使用我发现的解析器将其转换为HTML。
有什么建议么?
若要访问收件人,请遍历MailItem.Recipients集合并访问Recipient.Name和Recipient.Address属性。
与ItemSend事件触发时尚未设置与发送者相关的属性-最早可以访问发送者属性的时间是在"已发送邮件"文件夹上触发Items.ItemAdd事件时(使用Namespace.GetDefaultFolder对其进行检索)。
您可以阅读MailItem.SendUsingAccount。如果为空,请使用Namespace.Acounts集合中的第一个Account。然后,您可以使用Account.Recipient对象。
请记住,您不应盲目将外发项目投射到MailItem对象-您也可以拥有MeetingItem和TaskRequestItem对象。
好的,请使用Dmitry Streblechenko给我的信息以及我刚才在此处查找的其他一些信息,这是到目前为止的解决方案。
在ItemSend事件中,我首先确保已发送的电子邮件已移动到默认的已发送邮件文件夹。我正在测试使用gmail的Outlook,因此通常这些会在其他地方使用。 sendMailItems是作为类字段制成的,如果仅在Startup函数中声明它,则显然会被垃圾回收(对于MVC程序员来说,这有点奇怪:)。
当我回到办公室时,我将在交流中对其进行测试,希望一切顺利。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | public partial class ThisAddIn { public Outlook.Items sentMailItems; private void ThisAddIn_Startup(object sender, System.EventArgs e) { Application.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(ItemSend); sentMailItems = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail).Items; sentMailItems.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd); } void Items_ItemAdd(object item) { MessageBox.Show(((Outlook.MailItem)item).Subject); var msg = Item as Outlook.MailItem; string from = msg.SenderEmailAddress; string allRecip =""; foreach (Outlook.Recipient recip in msg.Recipients) { allRecip +="," + recip.Address; } } private void ItemSend(object Item, ref bool Cancel) { if (!(Item is Outlook.MailItem)) return; var msg = Item as Outlook.MailItem; msg.DeleteAfterSubmit = false; // force storage to sent items folder (ignore user options) Outlook.Folder sentFolder = this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail) as Outlook.Folder; if (sentFolder != null) msg.SaveSentMessageFolder = sentFolder; // override the default sent items location msg.Save(); } //Other auto gen code here.... } |