首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C#获取MS Outlook2007电子邮件正文中的选定文本

C#获取MS Outlook2007电子邮件正文中的选定文本
EN

Stack Overflow用户
提问于 2012-02-07 16:58:02
回答 1查看 3.1K关注 0票数 1

我使用的是C#和outlook-addin。

我希望用户能够选择邮件消息/正文的一部分,我希望能够复制所选项目,并将其存储到sql server数据库中。

代码语言:javascript
复制
Outlook.Application myApplication = Globals.ThisAddIn.Application;
Outlook.Explorer myActiveExplorer = 
    (Outlook.Explorer)myApplication.ActiveExplorer();

Outlook.Selection selection = myActiveExplorer.Selection;

if (selection.Count == 1 && selection[1] is Outlook.MailItem)
{
    Outlook.MailItem mail = (Outlook.MailItem)selection[1];

    mail.Copy(); // currently opened mail

    Outlook.MailItem mailItem = (Outlook.MailItem)
        myApplication.CreateItem(
        Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

    mailItem.Subject = mail.Subject;
    mailItem.To = mail.To;

    mailItem.Body = ?????         // copy only selected text/images of user 

    mailItem.Importance = Outlook.OlImportance.olImportanceLow;
    mailItem.Display(true);
}

mailITem.Body上,我只想粘贴选定邮件(当前打开的电子邮件)中用户的选定文本/图像。

我找不到paste方法,我如何实现它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-08 14:06:51

Outlook无法获取邮件正文中的选定文本,因此请将outlook转换为word编辑器,以便您可以执行以下3个步骤:

代码语言:javascript
复制
1. get the mail total body
2. use the word editor based on the **microsoft.office.Interop.word** dll
3. select the text and to store the any string

首先添加dll引用

代码语言:javascript
复制
object oItem;
Outlook.Application oApp=new Outlook.Application();
Outlook.Explorer oExp=oApp.ActiveExplorer();
Outlook.Selection oSel= oExp.Selection;
for (i = 1; i <= oSel.Count; i++)
{
    oItem = oSel[i];
    Outlook.MailItem oMail = (Outlook.MailItem)oItem;
    Outlook.Inspector inspector = oMail.GetInspector;

    // Obtain the Word.Document object from the Inspector object
    Microsoft.Office.Interop.Word.Document document = 
        (Microsoft.Office.Interop.Word.Document)inspector.WordEditor;

    mailItem.Body = document.Application.Selection.Text;
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9173401

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档