【问题标题】:how to get embed image from current outlook email with c#?如何使用 c# 从当前的 Outlook 电子邮件中获取嵌入图像?
【发布时间】:2013-01-16 23:15:24
【问题描述】:

我正在 Visual Studio 2010 中使用 c#.net 开发 Outlook 2010 插件。

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

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

我试图从谷歌上找到,但他们都展示了如何在电子邮件中嵌入图像。 但我想从 Outlook 电子邮件中获取嵌入图像。

谁能帮帮我?

【问题讨论】:

    标签: c# outlook-addin outlook-2010


    【解决方案1】:

    您应该可以使用: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");
            }
        }
    }
    

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

    【讨论】:

    • 非常感谢格雷格。你的代码解决了我的问题。非常感谢。
    猜你喜欢
    • 2010-10-01
    • 1970-01-01
    • 2022-09-25
    • 2012-03-30
    • 2021-12-23
    • 1970-01-01
    • 2011-03-15
    • 2010-11-18
    • 2015-12-20
    相关资源
    最近更新 更多