0

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.

AlexiAmni
  • 382
  • 1
  • 15
Carlo Goretti
  • 47
  • 1
  • 10
  • 1
    Possible duplicate of [How to solve COM Exception Class not registered (Exception from HRESULT: 0x80040154 (REGDB\_E\_CLASSNOTREG))?](https://stackoverflow.com/questions/1496214/how-to-solve-com-exception-class-not-registered-exception-from-hresult-0x80040) – Matěj Štágl Aug 15 '18 at 07:28
  • But it cant find a solution to my problem there.. – Carlo Goretti Aug 15 '18 at 07:43
  • 1
    There is several problems with Office Interop. First of all check if you have installed Outlook in same version as the referenced assemblies. – TcKs Aug 15 '18 at 08:58

1 Answers1

1

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.

Handbag Crab
  • 1,488
  • 2
  • 8
  • 12
  • If all you want to do is send an email, why not look into [System.Net.Mail](https://msdn.microsoft.com/en-us/library/system.net.mail%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396)? This is the .NET API for sending emails. – Handbag Crab Aug 15 '18 at 18:26
  • ye thanks! i think that the problem is that i dont have the office package on my computer.. i thought that you could use the windows mail. – Carlo Goretti Aug 15 '18 at 18:30