none
unable to open .eml file in outlook 2007

    Question

  • hi I am opening .eml using outlook 2007 it says object reference not set to an instance of an object and opening outlook windiw with my mail as attachment. howeer not opening my .eml mail.

    could you please help.

     

    Thursday, August 05, 2010 8:52 AM

Answers

  • That code doesn't use Redemption or the Outlook object model. So it's hard to say what's not working or why or much of anything else.

    Assuming this is an Outlook addin that has an _outlook object that's your Outlook.Application object, and that Redemption is registered, the code to open an eml file would look something like this:

    Outlook.NameSpace _ns = _outlook.GetNameSpace("MAPI");

    Redemption.RDOSession _rdo = new Redemption.RDOSession;

    _rdo.MAPIOBJECT = _ns.MAPIOBJECT;

    Redemption.RDOFolder _inbox = _rdo.GetDefaultFolder(Redemption.rdoDefaultFolders.olFolderInbox);

    Redemption.RDOItems _items = _inbox.Items;

    Redemption.RDOMail _mail = _items.Add("IP.Note");

    const int olRFC822 = 1024;

    _mail.Import("path to the eml file", olRFC822);

    _mail.Save();

    That will create a new item in the Inbox from the EML file at the path specified and save it.

     


    Ken Slovak MVP - Outlook
    • Marked as answer by Bessie Zhao Thursday, August 12, 2010 9:25 AM
    Wednesday, August 11, 2010 1:20 PM
    Moderator

All replies

  • The Outlook 2007 object model has no method for opening .eml files. You'd need to use the third-party Outlook Redemption library instead. 

    Thursday, August 05, 2010 10:16 AM
    Moderator
  • hi,

    could you please help me to use this redemption in my  c# code, 

    Thursday, August 05, 2010 10:36 AM
  • Sorry, no, I don't write C# code. Maybe someone else can help with that. In the meantime, the Redemption web site has detailed documentation. You can read about the RDOMail.Import method here: http://www.dimastr.com/redemption/rdo/rdomail.htm#methods
    Thursday, August 05, 2010 11:11 AM
    Moderator
  • What is your existing code that does not work?
    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Thursday, August 05, 2010 2:16 PM
  • Hello azra2009,

    How this issue is going on in your side? As Dmitry asked for, please show the code here. So that, we could see this issue on our side.

    Best regards,
    Bessie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, August 11, 2010 7:51 AM
  • hi

    PLEase fidn the code

     public override void EmailReceived(SPList list, SPEmailMessage emailMessage, string receiverData)
        {
          
          SPSecurity.RunWithElevatedPrivileges(delegate()
          {
            try
            {          
              
              
              //Declaration Of Variables.
              string strTo = ""; string strSubject = ""; string strBody = ""; string strCC = ""; string strFrom = ""; string strCreatedBy = ""; string strImportance = "";
              base.EmailReceived(list, emailMessage, receiverData);
              SPView view = list.DefaultView;
              //Getting MailMessage Values In String Variables.
              strSubject = emailMessage.Headers["Subject"].ToString();
              strBody = emailMessage.HtmlBody.ToString();
              strTo = emailMessage.Headers["To"].ToString();
              strFrom = emailMessage.EnvelopeSender.ToString();
              strCreatedBy = emailMessage.Headers["From"].ToString();
              if (emailMessage.Headers["CC"] != null)
              { strCC = emailMessage.Headers["CC"].ToString(); }
              if (emailMessage.Headers["Importance"] != null)
              { strImportance = emailMessage.Headers["Importance"].ToString(); }
              
              SPListItem oListItem = list.Items.Add();
              if (!list.Fields.ContainsField("Priority"))
              {
                list.Fields.Add("Priority", SPFieldType.Text, true);
                view.ViewFields.Add("Priority");
                view.Update(); 
              }                  
              
              oListItem["Title"] = strSubject;
              oListItem["E-Mail To"] = strTo;
              oListItem["E-Mail From"] = strFrom;
              oListItem["Body"] = strBody;
              oListItem["Priority"] = strImportance;
              oListItem.Update();
    
               //Get the Message Stream to save it as .eml.          
              byte[] content = null;
              string strPath = "c:\\SharePointMailDrop\\";
    
              using (Stream objMessageStream = emailMessage.GetMessageStream())
                {
                  content = new byte[objMessageStream.Length];
                  objMessageStream.Read(content, 0, (int)objMessageStream.Length);
                  objMessageStream.Close();
    
                  if (!Directory.Exists(strPath))
                    {
                      Directory.CreateDirectory(strPath);
                    }
    
                using (FileStream messageFileStream = new FileStream(strPath + strSubject +".eml", FileMode.Create))
                  {
                    messageFileStream.Write(content, 0, content.Length);             
                    list.RootFolder.Files.Add(strSubject +".eml", messageFileStream);
                    messageFileStream.Close();
                  
                  }             
              
        
                }
              list.Update();      
               
              
              
            }
            catch (System.Exception ex)
            {
              SPUtility.TransferToErrorPage(ex.Message.ToString());
            }
          });
      }
    

    Wednesday, August 11, 2010 8:47 AM
  • That code doesn't use Redemption or the Outlook object model. So it's hard to say what's not working or why or much of anything else.

    Assuming this is an Outlook addin that has an _outlook object that's your Outlook.Application object, and that Redemption is registered, the code to open an eml file would look something like this:

    Outlook.NameSpace _ns = _outlook.GetNameSpace("MAPI");

    Redemption.RDOSession _rdo = new Redemption.RDOSession;

    _rdo.MAPIOBJECT = _ns.MAPIOBJECT;

    Redemption.RDOFolder _inbox = _rdo.GetDefaultFolder(Redemption.rdoDefaultFolders.olFolderInbox);

    Redemption.RDOItems _items = _inbox.Items;

    Redemption.RDOMail _mail = _items.Add("IP.Note");

    const int olRFC822 = 1024;

    _mail.Import("path to the eml file", olRFC822);

    _mail.Save();

    That will create a new item in the Inbox from the EML file at the path specified and save it.

     


    Ken Slovak MVP - Outlook
    • Marked as answer by Bessie Zhao Thursday, August 12, 2010 9:25 AM
    Wednesday, August 11, 2010 1:20 PM
    Moderator