Reputation: 317
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.
Upvotes: 0
Views: 1109
Reputation: 66215
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)
.
Upvotes: 1