Error Microsoft.office.interop.outlook in c# asp.net

Poonam Wandhare 0 Reputation points
2023-05-27T11:09:53.65+00:00

Using interop.outlook to send mail using asp net and works fine on local computer.but giving error on server like could not load file or assembly 'office, version=14.0.0.0, culture= neutral, publickeytoken.........' help me it's very urgent.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,404 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,604 questions
Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
5,054 questions
{count} votes

2 answers

Sort by: Most helpful
  1. AgaveJoe 27,581 Reputation points
    2023-05-27T13:35:10.32+00:00

    Office interop requires that Office is installed which is unusual for a web server. Also, Office interop is not supported or recommended on a web server because interop opens an instance of Outlook on the server. See the official documentation. Considerations for server-side Automation of Office

    If you are just sending email then use SMTP or a service like SendGrid.


  2. Albert Kallal 5,226 Reputation points
    2023-05-27T17:09:09.8166667+00:00

    As noted, it going to be quite difficult to setup + install and have a working copy of Office/Outlook on the server. And as pointed out, this setup not really supported, and one stray "prompt" by office, and your server going to be "stuck" waiting for user interaction on the server.

    And it also not a setup that is supported.

    .net has several email systems built in, and I had great success using SmtpClient.

    About the only issue you might want to consider is bulding some kind of "template system in which a email template of some type can be saved, and then in the template you allow free markup, and JUST before you send, you have a bit of code that say takes one row of a database, and "replaces" some made up fields you have in that template.

    So, for example I use a HTML editor, and thus say have this:

    User's image

    so, all I do is pull the above record (a row in email templates table), do a replace on the fields in the above (anything like [SomeColumName], and then send via smtp (system.net.mail).

    And using the above idea of a HTML editor? Well, you can even paste logo's and pictures into the above. I am using html editor from the ajaxtoolkit, but ckedit would have been even better, and perhaps I'll get around to changing over the HTML editor. But with a HTML editor, you can make VERY nice looking templates, and not have to write "in code" a bunch of messey markup. (which I suspect is why you wanted to use Outlook in the first place --- to have a nice formatted email).

    The other issue?

    Well, if you web server is running as x64 bits, then you have to install office/outlook x64, and thus matching up the bit size of office install to the bit size of your running server is required. In other words, if you intstall office x32, then you you have to force + run the web site as x32 bits. Even this issue is thus another hassle and support breakage point.

    As noted here, using outlook to send emails from a web server is not at all going to work well, and is not really supported. Worse yet, Outlook often will prompt the user and require interaction - something that you can't control or do well at all attempting to use outlook by automation.

    Use one of the .net email systems - there are several, they are built in, and they all work quite well, and they don't require you to "try" and setup office + outlook to run on the web server. And such a setup is not going to be all that thread safe either.

    0 comments No comments