Open New Outlook email window on clinet machine - c#

I have a C# MVC application. I am using Outlook Interlop to create and open new mail through the application with contents and attachments pre-populated.
I get the desired functionality when I run the application locally on my development machine.
When I deploy the same application to server (2012 R2), the outlook new email window does not open on the client side.
Is is possible to open new outlook email window on client machine with the interlop code running on server. (Every user of the application has Outlook installed on their machine).
I have just installed Outlook 2013 on the server. Is there anything else I need to do on the server to make this work.
Any help would be appreciated as I have been struggling a lot to make this work.
Are there any alternative solutions to achieve the same?
Thanks in advance.

No, firstly, Outlook cannot run in a service such as IIS.
Even if it could, it would still be displayed on the server side.
You can dynamically generate an EML (MIME) message on the server. When the user on the client side downloads it, Outlook will display it. If you want the message to be displayed unsent, make sure you include X-Unsent MIME header (set its value to 1).

Code running on the server makes stuff happen on the server. It works on your dev machine because it's both client and server, it won't work on other people's machines. In addition to that, I believe the Office Interop stuff specifically says it's not for use on a server (for both technical and legal reasons).
If you want to pop up a message pre-populated with some values on a client machine, you do have the option of the mailto link, but I believe it is only plain text with no attachments.

Related

Accessing Outlook REST API from C# Console App on Windows XP

I'm updating a very old VB.NET console application to C#. The old application used the Domino libraries to send and search through received email through a Lotus Notes client.
My organization has since migrated all email to Office 365 and the Lotus Notes server will be retired soon. I need to be able to send emails through the Outlook REST API, and use the API to search for any email received since the last time the app ran with a specific key word in the subject (no need to actually read the email, just the subject.)
I've set up the app in https://dev.outlook.com/AppRegistration, checked all the Mail API boxes and copied the Client ID. But now I'm unsure how to proceed, since every tutorial I see involves an interactive session where the user grants access to the application. My application needs to be able to run unattended. No live interaction will be possible.
To further complicate the issue, I'm developing this app using Microsoft Visual C# 2010 Express on a Windows XP virtual machine. I could probably get our IS department to upgrade the virtual machine, but most likely Windows 7/Visual Studio 2013 will be as up-to-date as I can get.
Can anyone point me to a tutorial for authenticating with the Outlook REST API in a C# .NET console application without requiring user interaction?

Error with Excel and C# when logged off the server

I have written a Windows Service in C#. My service is meant to open an Excel macro-enabled workbook (this is in Excel 2010). I have installed this service on our server which is running Windows Server 2008 64-bit. My service seems to have a problem launching Excel when no one is logged on the server, does anyone have a solution to this?
I get the following error:
System.Runtime.InteropServices.COMException (0x8000401A): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 8000401a.
Excel is installed on the server, the service works fine when I am logged on the server but once all users have logged off, I get the above error. I would like the service to launch my Excel workbook regardless of an open session on the server or not.
My service seems to have a problem launching Excel when no one is logged on the server, does anyone have a solution to this.
Of course it has a problem. Windows Services cannot show a user interface, so how would you expect it to launch a GUI application like Microsoft Excel when there is no user logged in?
The specific COM error code that you receive means:
8000401a: The server process could not be started because the configured identity is incorrect. Check the username and password.
In other words, Excel is trying to start as an interactive user, which refers to the user that is currently logged on directly to the server console. Since no user is logged on, no interactive user exists, and the application fails when it tries to assume this identity.
The design was broken anyway: Excel was not designed to be run from a Windows Service. Create a standard Windows application instead. If you need it to run in the background without a UI of its own, don't create a window.
Basically, Cody Gray's answer is right. In the past I had a need to launch Excel from a Windows Service in order to print the file.
We were able to get past that kind of errors by setting the service to run as a specific user account and from time to time, log on as that user account and try to launch the files that failed to see the error messages popped up by Excel.
In your case, it is possibly because Excel is started for the first time and it asks you for something like your initials.
Are you using Office Automation to start Excel? Sorry, but Office Automation is not supported in service processes. It is designed to work only in an interactive process.
If you're lucky, Using Office Automation from a service process won't work. If you're not lucky, it will appear to work, and you'll actually put your application into production. You'll then start finding random bugs which are very difficult to reproduce, and even more difficult to fix without breaking something else.
That will be due to the fact that the real bug is a design bug - you used Office Automation from a service process.
Take it from the Voice of Experience...

How do I access Outlook mails with ASP.NET?

I'm trying to write an asp.net (using c#) app that accesses my Outlook mailbox and display the messages. I searched on google but couldn't find useful info, any help is appreciated?
You must be aware of the fact that outlook is running on user local machine, and your ASP.NET application is running on some server and there is no way that your server side ASP.NET code can use Outlook local data.
AFAIK only way to do something like that would be creating outlook addin that will export all mails to ASP.NET application
If you are using Exchange then you can use Exchange Web Services to read emails.
Please see here
Be very careful that you do not attempt to access Outlook on the server side by using the Automation interfaces. All of the Microsoft Office desktop applications are written to be run by an interactive user in a process with a message pump, with all synchronization happening via the UI. When you run them in a multi-threaded environment like ASP.NET, horrible things will happen. If you're lucky, the application will simply crash.
If you're not lucky, you can suffer from data corruption, random crashes in unrelated code, and all the other things that happen when an application corrupts memory.
You may also violate your license if the people accessing the Office application through your web site are not individually licensed to use the application on their desktop.
You can't connect to Outlook via C# (ASP.NET), but you can connect to your mailserver via POP3/IMAP to read the mail.
IMAP Client library using C#

C# / Exchange EMail Client

I need to create a very simple c# Windows Service to listen for, and process email wth special subject lines. I already have the code that process these emails working well. For ease of development, I just packaged the code in an "Outlook Addin" on my own machine, running under my own email account. Works great.
Now that it's working, I need to move this to the server. I have a special email account setup on the Exchange Server for this purpose. I really don't want Outlook running on the server. Is there some other way to login to this email account and listen for email from my Windows Service without using the Outlook client?
Thanks!
It sounds like your code is closely tied to Outlook, so you may have to change your approach for the server. I faced exactly the same problem last year and considered the following options :
CDO (not supported by Microsoft with .NET due to some strangeness when running in process)
WebDAV for Exchange 2003
Web Services for Exchange 2007 (great example in the link)
You also need to ask yourself - do you actually need your program to check the mail server? I couldnt use any of the above options so ended up having one of the mail admins set up an exchange rule that dropped the emails/attachments into a special folder on the server. I could then process the files at my leisure. Worked extremely well and much easier to maintain than directly interrogating the mail server through code.
If your exchange admin has enabled it you can use IMAP or POP3 to connect to the server.
You can also use MAPI to connect as well.
You can find a number of libraries (free and otherwise) for doing all three.
I have had good experience with MailBee IMAP but there are definitely free alternatives if you only need to do some simple functionality.

Opening mail.box file in Domino Server

I want to programmatically access Mail.box file in Domino Server.
Using C#.
Before opening it i was to see it's contents.
My question is that how can we open file with .box extension?
Especially Mail.box file in Domino Server.
Not sure I understand you fully. Are you saying that code like this doesn't work when attempting to access the mailbox on the server?
Domino.NotesDatabase database = session.GetDatabase("", "mail.box", false);
Mail.box is in fact a notes database. So opening it like a normal database is possible. However this is managed exclusively by the server. Email messages appear in this database only momentarily. Literally for a second. The only messages you will be able to monitor are emails the SMTP process cannot send.
If this is your intention, I would suggest consulting a Notes Admin as I think you can configure the server to alert you in the case of "dead" emails.

Categories