0

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.

Community
  • 1
  • 1
tomet
  • 2,416
  • 6
  • 30
  • 45
  • Is there a reason why you aren't using the Exchange Web Services API? – Justin Helgerson Jun 14 '13 at 15:17
  • Well, it's more a practice and I'd like to do it this way if possible. – tomet Jun 14 '13 at 15:23
  • 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 Jun 14 '13 at 16:45

1 Answers1

0

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.

Community
  • 1
  • 1
Bearcat9425
  • 1,580
  • 1
  • 11
  • 12
  • Does secretImage variable point to a fully qualified file name? – Dmitry Streblechenko Jun 14 '13 at 16:27
  • I had the same problem with the Outlook 16.0 Object Library. You'd think they would have updated things and made COM/.net work together in harmony by now !! –  Oct 11 '17 at 15:37