0

i am trying to get Outlook features(attachments,mails,contacts) using c#.

sample Code:

using System.Text;
using Microsoft.Office.Interop.Outlook;

namespace Happy_bday_automation
{
    class Program
    {
        private void SendEmailtoContact(string name)
        {
            string subjectEmail = "Happy Bday" + name;
            string bodyEmail = "Meeting is one hour later.";
            ContactItem contact1 = new ContactItem();
            contact1.Email1Address=name+"@ca.com";
            this.CreateEmailItem(subjectEmail, contact1.Email1Address, bodyEmail);
        }
}
}

so when i am creating contactItem Object i am getting error like

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: Retrieving the COM class factory for component with CLSID {00061031-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

please suggest some solutions :)

thanks in advance.

Rotem Varon
  • 1,597
  • 1
  • 15
  • 32
vishnubvrit
  • 317
  • 1
  • 3
  • 14

1 Answers1

1

ContactItem is not a creatable object, only Outlook.Application is.

A new contact can be created either using Application.CreateItem(OlItemType.olContactItem) or using MAPIFolder.Items.Add("IPM.Contact"), where MAPIFolder is a contacts folder. The default Contacts folder can be retrieved using Application.Session.GetDefautlFolder(olFolderContacts).

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78