0
votes

I've got a file (a btmap called secretimage) that I want to attach to a mail when the user hits a button. I'ld like to use Outlook for this.

So this is what I've done:

using Outlook = Microsoft.Office.Interop.Outlook;
private void cmdSend_Click(object sender, EventArgs e)
    {
            Outlook.Application app = new Outlook.Application();
            Outlook.MailItem mail = new Outlook.MailItem();
            Outlook.Attachment attach = mail.Attachments.Add(secretImage, Outlook.OlAttachmentType.olByValue, 0, "Secret message");
    }

Though this gives me the following error:

Retrieving the COM class factory for component with CLSID {00061033-0000-0000-C000-000000000046} failed due to the following error: 80040154 Klasse nicht registriert (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

The last part is German, I don't know why, actually I've set the language to English. "Klasse nicht registriert" translates "Class not registered".

I tried to do what is recommended here: Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80040154 Though that didn't work.

Can anyone help me here? I'm really stuck.

1
Is there a reason why you aren't using the Exchange Web Services API?Justin Helgerson
Well, it's more a practice and I'd like to do it this way if possible.tomet
One of the problems you are going to run into with this method is that Outlook has security measures in place where you have to allow for an application to send on your behalf. It will prompt and there is no way to default that answer without using some software written specifically to suppress that message and answer it for you. This is not ideal for sending emails. I would suggest either usering Exchange Web services or allow for a machine to be SMTP and use the System.Net.Mail Namespace. How ever you can use the code I provided below to do this and I tested and it works.Bearcat9425

1 Answers

0
votes

Try this swap out your mail item for this code, taken from this link. 80040154 Class not registered ERROR in Outlook 2010 Add In

Microsoft.Office.Interop.Outlook.MailItem mail= app.CreateItem((OlItemType.olMailItem));

One of the problems you are going to run into with this method is that Outlook has security measures in place where you have to allow for an application to send on your behalf. It will prompt and there is no way to default that answer without using some software written specifically to suppress that message and answer it for you. This is not ideal for sending emails. I would suggest either using Exchange Web services or allow for a machine to be SMTP and use the System.Net.Mail Namespace. How ever you can use this code I provided to do this and I have tested and it works.