如何使用C#从当前Outlook电子邮件中获取嵌入图像? [英] how to get embed image from current outlook email with c#?

查看:97
本文介绍了如何使用C#从当前Outlook电子邮件中获取嵌入图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Visual Studio 2010中使用c#.net开发Outlook 2010加载项.

I am developing outlook 2010 add-in with c#.net in visual studio 2010.

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

I want to get embed image from current email ( not attached) in to my form region.

如何从Outlook电子邮件中获取嵌入图片?

how to get embed image from outlook email ?

我试图从Google上查找,但是所有这些都显示了如何在电子邮件中嵌入图片. 但我想从Outlook电子邮件中获取嵌入式图像.

I tried to find out from google but all of them shows how to embed image in email. but i want to get embedded image from outlook email.

有人可以帮我吗?

推荐答案

您应该可以使用:Microsoft.Office.Interop.Outlook.这是命名空间.您可能不得不将其视为附件;将其保存到另一个文件夹.然后从那里递归提取数据.

You should be able to use: Microsoft.Office.Interop.Outlook. Here is a huge list of items within the Namespace. You may have to treat it like an attachment; save it to another folder. Then recursively pull the data from there.

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");
        }
    }
}

这会将嵌入或附加的项目保存到您选择的目录中;那么您可以随意选择自己操作的那些附加项目.希望至少可以使您指向写入方向.

That will save the embed or attached items to a directory of your choice; then you can simply manipulate those attached items however you choose. Hopefully that at least points you in the write direction.

这篇关于如何使用C#从当前Outlook电子邮件中获取嵌入图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆