如何使用c#从当前Outlook电子邮件中嵌入图像?

时间:2013-01-16 23:15:24

标签: c# outlook-addin outlook-2010

我正在使用visual studio 2010中的c#.net开发outlook 2010加载项。

我想将当前电子邮件(未附加)中的图片嵌入到我的表单区域。

如何从outlook电子邮件中嵌入图片?

我试图从谷歌中找到,但所有这些都展示了如何在电子邮件中嵌入图片。 但我想从outlook电子邮件中获取嵌入图像。

有人可以帮我吗?

1 个答案:

答案 0 :(得分:2)

您应该可以使用:Microsoft.Office.Interop.Outlook。以下是Namespace中的大量项目列表。你可能不得不像对待一样对待它;将其保存到另一个文件夹。然后从那里递归地提取数据。

private void ThisApplication_Startup(object sender, System.EventArgs e)
{
    this.NewMail += new Microsoft.Office.Interop.Outlook
        .ApplicationEvents_11_NewMailEventHandler(ThisApplication_NewMail);
}

private void ThisApplication_NewMail()
{
    Outlook.MAPIFolder inBox = this.ActiveExplorer()
        .Session.GetDefaultFolder(Outlook
        .OlDefaultFolders.olFolderInbox);
    Outlook.Items inBoxItems = inBox.Items;
    Outlook.MailItem newEmail = null;
    inBoxItems = inBoxItems.Restrict("[Unread] = true");
    try
    {
        foreach (object collectionItem in inBoxItems)
        {
            newEmail = collectionItem as Outlook.MailItem;
            if (newEmail != null)
            {
                if (newEmail.Attachments.Count > 0)
                {
                    for (int i = 1; i <= newEmail
                       .Attachments.Count; i++)
                    {
                        newEmail.Attachments[i].SaveAsFile
                            (@"C:\TestFileSave\" +
                            newEmail.Attachments[i].FileName);
                    }
                }
            }
        }
    }
    catch (Exception ex)
    {
        string errorInfo = (string)ex.Message
            .Substring(0, 11);
        if (errorInfo == "Cannot save")
        {
            MessageBox.Show(@"Create Folder C:\TestFileSave");
        }
    }
}

这会将嵌入或附加的项目保存到您选择的目录中;那么你可以简单地操纵那些你选择的附加物品。希望至少指出你的写作方向。