0
votes

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.

1
do u have this record in the registry? u can run regeditRotem Varon
Why is asp.net a tag?Enigmativity
Have you added the reference: stackoverflow.com/questions/17434620/…Rotem Varon
another possible solution (when u will provide more info we will be able to help better): stackoverflow.com/questions/1036856/…Rotem Varon

1 Answers

1
votes

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).