how to get embed image from current outlook email with c#?

与世无争的帅哥 提交于 2019-12-25 07:25:40

问题


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.

how to get embed image from outlook email ?

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.

can anyone help me please ?


回答1:


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.



来源:https://stackoverflow.com/questions/14369631/how-to-get-embed-image-from-current-outlook-email-with-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!