How to fix this issue: COM Exception Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))?

-2

Im trying to make a program who will send a mail but when im trying to send it it only come up that im need to fix this problem:

COM Exception Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

Here is my code for this:

Outlook.Application app = new Outlook.Application();
 Outlook.MailItem mailItem = app.CreateItem(Outlook.OlItemType.olMailItem);

            mailItem.Subject = "Password recovery";
            mailItem.To = MailTxt.Text;
            mailItem.HTMLBody = "Your new password is: " + RecoveryNewPW + ". <br/> If you want to change the password, you need to do following:<ul><li>Login and go to settings tab.</li><li>Write old password in the first textbox.</li><li>Write the new password in the second textbox</li><li>Write the new password again in the third textbox</li><li>Done!</li></ul>";
            mailItem.Send();
            MessageBox.Show("Sent!");

Im thankful for help! I know that this question alredy exists on thise site but i couldnt fix the problem trough the other ones.

c#
winforms
outlook
asked on Stack Overflow Aug 15, 2018 by Carlo Goretti • edited Aug 15, 2018 by AlexiAmni

1 Answer

0

If you have the 32bit version of Office installed then you need to open the Properties screen in Visual Studio and select "All Configurations" from the "Configuration" dropdown, then select "x86" from the "Platform Target" dropdown.

Set to x86

You can tell what version of Office you have by where it's installed. If it's installed in "Program Files (x86)" then it's 32bit. If it's in "Program Files" it's the 64bit version.

answered on Stack Overflow Aug 15, 2018 by Handbag Crab

User contributions licensed under CC BY-SA 3.0